#include<stdio.h>
#include<conio.h>
void sump(int
n1,int n2,int s1[],int s2[]){
int
temp,s[100],c=0,sum=0,i,j,k;
for(i=n1-1,j=n2-1;j>=0;i--,j--){
sum=s1[i]+s2[j]+c;
if(sum>9){
sum=sum-10;
c=1;
}
else{
c=0;
}
s[i]=sum;
//printf("%d
",sum);
}
if(i>=0){
for(k=i;k>=0;k--){
sum=s1[k]+c;
if(sum>9){
sum=sum-10;
c=1;
}
else{
c=0;
}
s[k]=sum;
if(k==0 &&
c==1){
for(i=n1;i>0;i--){
temp=s[i-1];
s[i]=temp;
}
n1=n1+1;
s[i]=c;
//printf("c=%d
",c);
}
}
}
printf("%d",s[0]);
for(i=1;i<n1;i++)
printf(",%d",s[i]);
//printf("%d",s[n1]);
}
void main(){
int
s11[100],s22[100],n11,n22,i1,j1;
clrscr();
scanf("%d",&n11);
for(i1=0;i1<n11;i1++)
scanf("%d,",&s11[i1]);
scanf("%d",&n22);
for(j1=0;j1<n22;j1++)
scanf("%d,",&s22[j1]);
if(n11>n22 ||
n11==n22)
sump(n11,n22,s11,s22);
else
sump(n22,n11,s22,s11);
getch();
}
No comments:
Post a Comment