各进制转换
2016-07-23 17:03
471 查看
通过数据库转换:
#include <iostream>
using namespace std;
int main()
{
int test=64;
cout<<"DEC:"<<test<<endl;
cout<<"OCT:"<<oct<<test<<endl;//八进制
cout<<"HEX:"<<hex<<test<<endl;//十六进制
return 0;
}
运用递归运算:
#include <iostream>
using namespace std;
int main()
{
int test=64;
cout<<"DEC:"<<test<<endl;
cout<<"OCT:"<<oct<<test<<endl;//八进制
cout<<"HEX:"<<hex<<test<<endl;//十六进制
return 0;
}
运用递归运算:
#include <iostream> using namespace std; void foo(int n, int base) { if (n == 0) { cout << endl; return; } foo(n / base, base); cout << n % base; } int main() { int i = 12345; //cin >> i; foo(i, 8); }辗转相除法:
#include <math.h> int L[100]; using namespace std; int main() { int a,A; _int64 hk,ls; while(scanf("%d",&a),a) { scanf("%I64d%I64d",&hk,&ls); A=hk+ls; int i=0; if(A==0) { printf("0\n"); continue; } while(A) { L[i++]=A%a; A=A/a; } for(int j=i-1;j>=0;j--) { printf("%d",L[j]); } cout<<endl; } return 0; }
相关文章推荐
- 再回首-无符号大整数加法
- HTTPS工作原理
- 为什么一些api暴露的id不是整数
- dubbo,MemCache和Nginx初识等服务器组件
- mysql 下 计算 两点 经纬度 之间的距离 含具体sql语句
- parseQueryString
- 深入理解JAVA I/O系列三:字符流详解
- Socket解决粘包问题2
- POJ 2121
- 通过金矿模型介绍动态规划
- 代码块的执行前后
- CCNA系列十二之ACL
- Deep learning 译文 -- 第二部分
- OTP研究记录
- 【iOS开发】在界面上显示“HELLO”
- Codeforces 701B Cells Not Under Attack(模拟)
- Node.js 初体验
- Codeforces Round #364 (Div. 2) C.They Are Everywhere
- 新手老手都离不开八大开发工具
- 计算机科学小知识