Home > Back-end >  How to use C, decimal turned the cycle of binary code? The cyclic code has to write!
How to use C, decimal turned the cycle of binary code? The cyclic code has to write!

Time:09-22

#include
using namespace std;
Int main ()
{
Int n, k=0, a [1000]={0};
Cout<& lt;" Please enter a positive integer n!" cin> n;
Cout<& lt;" N the remainder is: ";
While (n!=0)
{
A [k]=n % 2;
K++;
N/a=2;
}
For (int j=k - 1; J>=0; J -)
CoutCoutsystem("pause");
Return 0;
}

CodePudding user response:

You the while and a for loop, isn't it?

CodePudding user response:

Loop out is wrong, is a problem of array

CodePudding user response:

reference 1st floor ooolinux response:
you while and a for loop, isn't it?

What I want is can be repeated many times to enter a positive integer, then run, before I use the loop statement, input 10 for the first time, the result is: 1010; 11 then input, the result becomes: 10111010, I want to solve this problem, how to get the desired results, using an array,

CodePudding user response:

Cycle time at the start of the k=0;

CodePudding user response:

 # include & lt; Iostream> 
#include

using namespace std;
Int main (int arg c, char * argv [])
{
Int SJZ;
Char ejz [33].

While (1)
{
Memset (ejz, '\ 0', sizeof (ejz));
Cout<& lt;" PLS input a num (& lt;=32 bit, signed) : ";
cin> SJZ;
for(int i=0; i<32. I++)
{
Ejz [I]='0' + ((SJZ & gt;> I) & amp; 0 x01);
}
Cout & lt; }
Return 0;
}

CodePudding user response:

 # include & lt; Iostream> 

using namespace std;
Int main (int arg c, char * argv [])
{
While (1)
{
Int SJZ;
Char ejz [33]={0};
Cout<& lt;" PLS input a num (& lt;=32 bit, signed) : ";
cin> SJZ;
for(int i=0; i<32. I++)
{
Ejz [I]='0' + ((SJZ & gt;> I) & amp; 0 x01);
}
Cout & lt; }
Return 0;
}

CodePudding user response:

 # include & lt; Iostream> 

using namespace std;
Int main (int arg c, char * argv [])
{
While (1)
{
Int SJZ;
Char ejz [33]={0};
Cout<& lt;" PLS input a num (& lt;=32 bit, signed) : ";
cin> SJZ;
for(int i=0; i<32. I++)
{
Ejz [31 - I]='0' + ((SJZ & gt;> I) & amp; 0 x01);
}
Cout & lt; }
Return 0;
}
  • Related