2022年应用多文件数组处理大整数的加减乘除_第1页
2022年应用多文件数组处理大整数的加减乘除_第2页
2022年应用多文件数组处理大整数的加减乘除_第3页
2022年应用多文件数组处理大整数的加减乘除_第4页
2022年应用多文件数组处理大整数的加减乘除_第5页
已阅读5页,还剩2页未读 继续免费阅读

付费下载

下载本文档

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

文档简介

1、.可编辑版可编辑版.可编辑版#include stdio.h#include stdlib.h#include string.h#include f2.h#include f3.h#include f4.h#include f5.h#define max_len 100int an1max_len+10=0;int an2max_len+10=0;int resultmax_len+10=0;char str1max_len+10;char str2max_len+10;void main()int flag=1;printf(=n);printf(=1:求和=n);printf(=2:求差=

2、n);printf(=3:求积=n);printf(=4:求商=n);printf(=5:退出=n);printf(=n);while( flag != 0)printf(nPlease input your choice:); scanf(%d,&flag);switch(flag)default: printf(The num is not correct,please input again:n);break;case 1:add( an1 , an2 ); break;case 2:jian( an1 ,an2 );break;case 3:mul( an1 ,an2 );break;

3、case 4: div( an1 ,an2 );break;case 5:exit(0);.可编辑版可编辑版.可编辑版#includef2.h#includestdio.h#includestdlib.h#includestring.h#define max_len 100int add(int *an1 ,int *an2) char str1max_len+10; char str2max_len+10;scanf(%s,str1);scanf(%s,str2);int i,j; /存储的字符串整数转换到an1中去j=0;for(i=strlen(str1)-1;i=0;i-) an1j+

4、=str1i-0;j=0; for(i=strlen(str2)-1;i=0;i-) an2j+=str2i-0; for(i=0;i=10) /看是否进位 an1i-=10; an1i+1+; /进位 bool bStartOutput=false;/跳过多余的零 for(i=max_len;i=0;i-) if (bStartOutput) printf(%d,an1i); /多余零都跳过那么退出 else if(an1i) printf(The sum is %dn,an1i); bStartOutput=true; for(j=0;jmax_len+10;j+)an1j=0;an2j=

5、0;.可编辑版可编辑版.可编辑版 return 0; #include f3.h#include stdio.h#include stdlib.h#include string.h#define max_len 100int jian(int *an1,int*an2 ) char str1max_len+10; char str2max_len+10;int i,j;scanf(%s,str1);scanf(%s,str2);for(i=0;i=0;i-)an1j+=str1i-0;int nlen2=strlen(str2);j=0;for(i=nlen2-1;i=0;i-) an2j+=

6、str2i-0;for(i=0;imax_len;i+)if(an1i=0;i-) if (bStartOutput) printf(%d,an1i); /多余零都跳过那么输出 else if(an1i) printf(The result is %dn,an1i); bStartOutput=true; .可编辑版可编辑版.可编辑版 for(i=0;i=0;i-)an1j+=str1i-0;int nlen2=strlen(str2);j=0;for(i=nlen2-1;i=0;i-)an2j+=str2i-0;for(i=0;inlen2;i+)for(j=0;jnlen1;j+)resu

7、lti+j+=an2i*an1j; for(i=0;i=10)resulti+1+=resulti/10;resulti%=10; bool bStartOutput=false;/跳过多余的零 for(i=max_len;i=0;i-) if (bStartOutput) printf(%d,resulti); /多余零都跳过那么退出 else if(resulti) printf(The result is %dn,resulti);.可编辑版可编辑版.可编辑版 bStartOutput=true; for(j=0;j=0); bool bStartOutput=false;/跳过多余的零

8、 for(i=max_len;i=0;i-) if (bStartOutput) printf(%d,resulti); /多余零都跳过那么退出 else if(resulti) printf(The result is %dn,resulti); bStartOutput=true; for(j=0;j=0;i-) an1j+=str1i-0; int nlen2=strlen(str2); j=0; for(i=nlen2-1;i=0;i-) an2j+=str2i-0; if(nlen1nlen2) printf(0n); nlen1=sub(an1,an2,nlen1,nlen2);

9、if(nlen1=0); bool bStartOutput=false;/跳过多余的零 for(i=max_len;i=0;i-) if (bStartOutput) printf(%d,resulti); /多余零都跳过那么退出 else if(resulti) printf(The result is %dn,resulti); bStartOutput=true; for(j=0;jmax_len+10;j+)an1j=0;an2j=0; return 0; int sub(int*p1,int*p2,int nlen1,int nlen2) /返回值代表的是结果长度 /不够减返回-1,刚好减完返回0.可编辑版可编辑版.可编辑版 int i; if(nlen1=0;i-) if(p1ip2i) blarger=true

温馨提示

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

最新文档

评论

0/150

提交评论