my task is to convert decimal numbers to binary, but as we are beginners in programming I'm not allowed to use arrays, functions, etc. Just for and if and basic operations.
My code is:
#include <iostream>
int main()
{
int n;
int b;
std::cin >> n;
for (int i=n; n>0; --i) {
b = n%2;
std::cout << b;
n = n/2;
}
return 0;
}
It works, but it gives me the binary number in the wrong order, e.g. it's 0001 representing 4 instead of 1000. Could anyone help me please?