+ 3
Why this code is not right?
14 odpowiedzi
+ 5
Try in this way:-
#include <iostream>
using namespace std;
int main() {
int N;
int evens=0;
int odds=0;
int zeroes=0;
cin >> N;
for (int num=0; num<=N; num++) {
if (num==0) {
zeroes++;
}
else if (num%2==0) {
evens++;
}
else if (num%2 != 0) {
odds++;
}
}
cout << "The number of zeroes is " << zeroes << endl;
cout << "The number of evens is " << evens << endl;
cout << "The number of odds is " << odds;
return 0;
}
+ 2
I don't know why were you priting counts of number within loop..
And just check for zero before checking even
https://code.sololearn.com/c7WqlPDuTgtg/?ref=app
+ 1
Can you give some numbers to check with?
+ 1
One issue I found is that 0 is counted as evens, not zeroes.
+ 1
Problem is thar num%2==0 gives true also when num is 0, so you have to reorder your IF's
If (num==0) ...
else if (num%2==0)...
else /* if (num%2!=0) */ ...
+ 1
if num % 2
print it's odd, increment <odds>
else
if num
print it's even, increment <evens>
else
print it's zero, increment <zeroes>
+ 1
#include <iostream>
using namespace std;
int main() {
int N;
int evens=0;
int odds=0;
int zeroes=0;
cin >> N;
for (int num=0; num<=N; num++) {
if (num==0) {
zeroes++;
}
else if (num%2==0) {
evens++;
}
else if (num%2 != 0) {
odds++;
}
}
cout << "The number of zeroes is " << zeroes << endl;
cout << "The number of evens is " << evens << endl;
cout << "The number of odds is " << odds;
return 0;
}
+ 1
There can be at the most 1 zero,. N mod 2 gives whether the number is even or odd and you can take the respective sum 🤔
0
I did but something is not ok
0
Tell the input that shows wrong output
0
boonga important info, khm.
0
0 is even
0
OF THE TOPIC
0 and 1 are imagenary
2,4,8,10... are even numbers
3,5,7,9.... are odd numbers
Based on Square Theory.
Does MODULUS is dependent on that theory ?
0 % 1 = 0
1 % 1 = 0
2 % 1 = 0
...
How to transform this equation?
That's why modulus is mapping.
Modules derives that number is odd or even in programming.
0
OFF THE TOPIC
Higher Mathematics
√(-1) = √(-1)
√(-1)*1 = √(-1)
√(-1)*√(-1)*√(-1) = √(-1)
(-1)*√(-1) = √(-1)
- √(-1) = √(-1)
2*√(-1) = 0
This implies
√(-1) = 0
or
2 = 0 / √(-1) ... (I)
Assume √(-1) = iota
(0 * √-1) / (√-1)*(√-1) = 2
(0 * √-1) / (-1) = 2
(0 * √-1) = -2....(ii)
From equations (i) & (ii)
Division
(0 * √-1) / (0 * √-1) = 2 / -2
1 = -1
2 = 0
This tells that 2 is also imagenary.
iota is vector √-1 called i
x + iy + p + iq = (x + p) + i(y + q)
x + iy + p - iq = (x + p) + i(y - q)
(x + iy)*(p + iq) = (xp - yq) + i(xq + yp)
(x + iy)/(p + iq) = ( (xp - yq) + i(xq + yp) ) / (p*p + q*q)
Examples of complex numbers. Very useful in
image analysis
sound analysis
vector calculation
hyperbolic functions
sine cosine calculation using series
DHANANJAY PATEL