Home > Back-end >  Why the output of the binary, octal, not output
Why the output of the binary, octal, not output

Time:06-11

#include
#include
Int main ()
{
[100] long int a, s, b=0, x=0, n, f;
The scanf (" % ld ", & amp; A);
While (a!=0)
{
S [b]=a % 2;
A=a/2;
B=b + 1;
}
For (n=b - 1; n>=0; N -)
{
Printf (" % ld. "[n] s);
}
While (a!=0)
{
S [x]=a % 8;
A=a/8;
X=x + 1;
}
For (f=x - 1; F>=0; F -)
{
Printf (" % ld, "s [f]);
}
return 0;
}

CodePudding user response:

A after the binary conversion, has become a 0,
So, consider using a temporary variable to hold a, in a binary conversion, and then give the original value of the saved a assignment to a, let a reset,
 # include & lt; stdio.h> 
#include
Int main ()
{
[100] long int a, s, b=0, x=0, n, f;
The scanf (" % ld ", & amp; A);
Long int temp=a;//-- -- -- -- -- -- -- -- -- -- to define a temporary variable to hold a -- -- -- -- -- -- -- -- -- -- -- -- --
While (a!=0)
{
S [b]=a % 2;
A=a/2;
B=b + 1;
}
For (n=b - 1; N & gt;=0; N -)
{
Printf (" % ld. "[n] s);
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- when a value has been into 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
printf("\n");//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - a new line
A=temp.//-- -- -- -- -- -- -- -- -- a value is reset, the input values into the original -- -- -- -- -- -- -- -- -- -- -- --
While (a!=0)
{
S [x]=a % 8;
A=a/8;
X=x + 1;
}
For (f=x - 1; F & gt;=0; F -)
{
Printf (" % ld, "s [f]);
}
return 0;
}

The following for VS2015 debugging results

CodePudding user response:

reference 1st floor MianHou response:
a after binary conversion, has become a 0,
So, consider using a temporary variable to hold a, in a binary conversion, and then give the original value of the saved a assignment to a, let a reset,
 # include & lt; stdio.h> 
#include
Int main ()
{
[100] long int a, s, b=0, x=0, n, f;
The scanf (" % ld ", & amp; A);
Long int temp=a;//-- -- -- -- -- -- -- -- -- -- to define a temporary variable to hold a -- -- -- -- -- -- -- -- -- -- -- -- --
While (a!=0)
{
S [b]=a % 2;
A=a/2;
B=b + 1;
}
For (n=b - 1; N & gt;=0; N -)
{
Printf (" % ld. "[n] s);
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- when a value has been into 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
printf("\n");//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - a new line
A=temp.//-- -- -- -- -- -- -- -- -- a value is reset, the input values into the original -- -- -- -- -- -- -- -- -- -- -- --
While (a!=0)
{
S [x]=a % 8;
A=a/8;
X=x + 1;
}
For (f=x - 1; F & gt;=0; F -)
{
Printf (" % ld, "s [f]);
}
return 0;
}

The following for VS2015 debugging results

Oh oh, see, thank you very much for bosses

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html