Z

来源:互联网 发布:网络购物案例分析 编辑:程序博客网 时间:2024/04/30 09:56
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1
2
3
Sample Output
1
10

11


翻译过来就是转换二进制


解题思路:利用进制转换的规则就可以解决。


#include<stdio.h>void train(int n){int a[1000];int i=0,j;while(n>=2){a[i]=n%2;n=n/2;i++;}i--;printf("%d",n);for(j=i;j>=0;j--)printf("%d",a[j]);printf("\n");}int main(){int n;while((scanf("%d",&n))!=EOF){train(n);}return 0;}