任意数制转换c++代码.doc_第1页
任意数制转换c++代码.doc_第2页
任意数制转换c++代码.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

下面是一个用c+写的数制转换小程序,可以实现常见的数制之间的转换。 #include #include #define N 4 using namespace std;/定义函数 dectoother(),该函数能够将一个十进整数转换成其他进制的数 ,并将结果输出 void dectoother1(float number,int n) int outputN8 = 0,mod=0 ; int div=0; unsigned char bN=0; for(int i=0;iN;i+) bi=*( char *)&number+i); for(int i=0;iN;i+) div=bi; for(int j=0;j8;j+) outputij=div%n; div/=n; cout (number=0;i-) for(int j=7;j=0;j-) if(i=N-1&j=6)|(i=N-2&j=6)cout ; cout outputij; cout b) n endl ;/定义函数 dectoother(),该函数能够将一个十进整数转换成其他进制的数 ,并将结果输出 void dectoother1(int number,int n) int outputN8 = 0,mod=0 ; int div=0; unsigned char bN=0; for(int i=0;iN;i+) bi=*( char *)&number+i); for(int i=0;iN;i+) div=bi; for(int j=0;j8;j+) outputij=div%n; div/=n; cout (number=0;i-) for(int j=7;j=0;j-)cout outputij; cout ; cout b) n endl ;int gotoloop() /此函数询问用户是否退出程序 /询问是否退出 char c; loop1 : cout 是否退出程序?(Y/N); /* 通过 while 循环把输入流中的余留数据“吃”掉 */ while ( (c=getchar() != n & c != EOF ) ; ; switch(getchar() case n: case N: coutendl;return 1; case y: case Y: return 0; default :cout 输入错误!; goto loop1; /主函数 int main(int argc, char *argv) /程序介绍 cout *n * 此程序可以根据输入,将十进制数 *n * 转换成相应的其他进制的数并输出. *n *n; / 提示输入 loop : float fnumber=0; int dnumber=0,other=2,flag=0; cout 你将输入的数是:1,整数 2,浮点数 endl flag; if(1=flag) cout dnumber ; else cout fnumber ; cout 2,二进制n3,三进制n4,四进制n. endl other ; /调用数值转换函数 if(1=flag)dectoother1(dnumber,other) ; else decto

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论