2025-03-31 19:37:23 +08:00

37 lines
973 B
C

/*-----------------------------------------------------------------------
【程序设计】
-------------------------------------------------------------------------
题目:编写函数实现用除二取余的方法,把任意一个十进制正数的二进制序列输出
(不考虑溢出)
程序输入输出如下所示
Enter a decimal number: 2
The binary representation is: 10
-------------------------------------------------------------------------
------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
void decimalToBinary(int decimal)
{
int remainder;
int len = 0;
char binary[32];
int i;
if (decimal == 0)
{
printf("0");
return;
}
/**********Program**********/
/********** End **********/
printf("%s\n", binary);
}
int main()
{
int number;
printf("【Enter a decimal number: 】");
scanf("%d", &number);
printf("【The binary representation is: 】");
decimalToBinary(number);
}