Give you a number on base ten,you should output it on base two.(0 < n < 1000)
InputFor each case there is a postive number n on base ten, end of file.OutputFor each case output a number on base two.Sample Input
1
2
3
Sample Output
1
10
11
#include<stdio.h>
int main()
{
int n,k,t;
while(scanf("%d",&n)!=EOF)
{
k=0;
t=1;
while(n!=0)
{
k+=(n%2)*t;
n=n/2;
t*=10;
}
printf("%d\n",k);
}
return 0;
}
题解:多么可爱的水题!
本文介绍了一个简单的C程序,该程序能够将用户输入的十进制正整数转换为对应的二进制表示形式。通过使用取余运算和除法运算,程序能够有效地完成转换,并且支持0到999之间的任意整数。
1300

被折叠的 条评论
为什么被折叠?



