0
print all the numbers that do not exceed n the natural number and will give 1 balance when delivering each one on 2
#include <iostream> using namespace std; int main() { int n, m, r=0; cin>>n; for (int k = 0; n>k; k++) { m==k;} while(m!=0){ if(m%2==1){ r++; } m/=2; } cout<<r<<endl; return 0; } // I don't know where is my mistake
1 Respuesta
+ 1
I dont really get what you are trying to achieve.. but there are some mistakes in the code syntax:
m==k should be in m = k maybe because with == you are not assaigning a value but comparing it!
Also the curly braces position is not good I do believe!
If you want to print all numbers you should put thr cout inside the while loop and the while loop inside the for loop!