c语言二进制转化为十进制
Here you will get program to convert decimal to binary in C.
在这里,您将获得将C中的十进制转换为二进制的程序。
We can convert a decimal number into binary by repeatedly dividing it by 2 and storing the remainder somewhere. Now display the remainders in reverse order.
我们可以通过将十进制数重复除以2并将剩余的数存储在某处来将其转换为二进制数。 现在以相反的顺序显示余数。
Also Read: Convert Binary to Decimal in C
另请参阅: 在C中将二进制转换为十进制
将十进制转换为C中的二进制 (Convert Decimal to Binary in C)
#include<stdio.h>
int main()
{
int d,n,i,j,a[50];
printf("Enter a number:");
scanf("%d",&n);
if(n==0)
printf("\nThe binary conversion of 0 is 0");
else
{
printf("\nThe binary conversion of %d is 1",n);
for(i=1;n!=1;++i)
{
d=n%2;
a[i]=d;
n=n/2;
}
for(j=i-1;j>0;--j)
printf("%d",a[j]);
}
return 0;
}
Output
输出量
Enter a number:10
输入数字:10
The binary conversion of 10 is 1010
10的二进制转换为1010
翻译自: https://www.thecrazyprogrammer.com/2013/02/c-program-to-convert-decimal-number-to.html
c语言二进制转化为十进制