标签:style blog http io ar color os sp for
ACM队的队花C小+经常抱怨:“C语言中的格式输出中有十六、十、八进制输出,然而却没有二进制输出,哎,真遗憾!谁能帮我写一个程序实现输入一个十进制数n,输出它的二进制数呀?”
难道你不想帮帮她吗?^_^
0 1 2 10
0 1 10 1010
#include<stdio.h> #include<string.h> int main() { int i,n; int a[1000]; while(scanf("%d",&n)!=EOF) { i=0; memset(a,0,sizeof(a)); if(n==0) printf("0\n"); else{ while(n) { a[i]=n%2; n/=2; i++; } for(i=i-1;i>=0;i--) printf("%d",a[i]); printf("\n");} } return 0; }
标签:style blog http io ar color os sp for
原文地址:http://blog.csdn.net/hdd871532887/article/details/41653153