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
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;}
阅读全文
0 0
- z
- z
- Z
- Z
- Z
- Z
- Z
- Z
- [z]能笑吗?
- ping[z]
- 初吻z
- Z-index
- Z字型
- Ctrl + Z
- z-index
- Z - Atlantis
- awk --z
- 程序员z
- tomcat安装与myclipse版本兼容
- ip 命令 docker相关的网络命令 network namespace相关命令总结
- mysql修改默认编码集
- (笔记)数据结构2.1-线性表及其实现(一)
- QT html转excel
- Z
- 基于android Linux kernel 3.10.87分析
- springboot热部署
- Ubuntu的那点小事(一)
- 20.2 通用的重定向方法
- 三向城+香兰子
- 菱形继承问题分析及其在C++的解决方法(虚继承)
- PrintWriter和OutPutStream
- 179. Largest Number