大数加法
来源:互联网 发布:姆希塔良2017数据 编辑:程序博客网 时间:2024/05/18 01:44
#include"stdio.h"#include"string.h"#define NM 1001char a[NM],b[NM],sum[NM+1]={0};int main(){ int n,i,j,la,lb,k,l; scanf("%d",&n);//确定要计算多少组数 for(i=1;i<=n;i++) { scanf("%s%s",a,b); // 因大数所几十位上百位里能超过1001位//所数值类型都能表示出来只好用字符数组来表示 la=strlen(a);//得输入数据位数 lb=strlen(b); //把每位数分别加sum项用sum[0]表示位sum[1]表示十位 for(j=la-1,k=0;j>=0;j--)sum[k++]=a[j]-'0';//得每位表示数大小 for(j=lb-1,k=0;j>=0;j--) sum[k++]+=b[j]-'0';//与上面相应数相加此时某项大于等于10 l=la>lb?la:lb;//得长数据长度 for(j=0;j<l;j++) //逐扫描数据数组 if(sum[j]>=10)//某项大于等于10进位 {sum[j]-=10;sum[j+1]++; }/*notice here sum[j]>=10 not sum[j]>10*/ if(sum[j]) //总体进位多位数总长度加l++; printf("Case %d:\n%s + %s = ",i,a,b); for(j=l-1;j>=1;j--)//逆序打印即打印所谓位 { printf("%d",sum[j]); sum[j]=0; } printf("%d\n",sum[0]);//先把数组第位置0下轮做准备 if(i<n) //还初定好轮数换行 printf("\n"); } return 0;}
0 0
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- 大数加法
- And with Li Na out ahead of time
- HTTP Content-type
- in Roland Garros history, Australian
- It is because of the existence of this spell, t
- the transition had too many heroes bow
- 大数加法
- he new Australian Open Men's singles champion's performance at Roland Garros is "equal".
- HSQL内存数据库的配置
- google,Hotpo
- Agassi, Federer, Nadal, Germany, big Williams, Sharapova
- s also the world's top three Stanislas
- the last time do this the "lucky", or 1992 curry
- WINDOWS 7 配置驱动开发环境(wdk7.60)
- delegate paint