26th Aug 2020, 3:50 PM
TeaserCode
14 Answers
+ 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; }
28th Aug 2020, 11:24 AM
Minhazur Rahaman Ratul
Minhazur Rahaman Ratul - avatar
+ 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
26th Aug 2020, 4:23 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
Can you give some numbers to check with?
26th Aug 2020, 3:54 PM
Ipang
+ 1
One issue I found is that 0 is counted as evens, not zeroes.
26th Aug 2020, 4:15 PM
boonga
boonga - avatar
+ 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) */ ...
26th Aug 2020, 4:20 PM
Bilbo Baggins
Bilbo Baggins - avatar
+ 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>
26th Aug 2020, 4:21 PM
Ipang
+ 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; }
26th Aug 2020, 4:26 PM
Ruba Kh
Ruba Kh - avatar
+ 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 🤔
28th Aug 2020, 4:00 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
I did but something is not ok
26th Aug 2020, 3:57 PM
TeaserCode
0
Tell the input that shows wrong output
26th Aug 2020, 4:13 PM
Namit Jain
Namit Jain - avatar
0
boonga important info, khm.
26th Aug 2020, 4:16 PM
TeaserCode
0
0 is even
26th Aug 2020, 4:27 PM
Namit Jain
Namit Jain - avatar
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.
28th Aug 2020, 5:17 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
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
28th Aug 2020, 11:33 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar