PS:下面的代码输出格式有问题,,,,,思路是对的
1 #include<stdio.h> 2 #include<string.h> 3 #define N 102 4 char s[N]={0}; 5 char s1[N]={0}; 6 int a1[N]={0}; 7 void add(char s1[],int a1[])//传入两个地址 8 { 9 int len1,i,j; 10 int a2[N]; 11 memset( a2 , 0 , sizeof(a2)) ;//初始化a2 12 len1 = strlen(s1); 13 j = 0; 14 for(i = len1 - 1;i>=0;i--)//i从最左边开始 15 { 16 a2[j] = s1[i] - '0';//暂时将这串字母的顺序改变并且保存到a2[]中 17 j++; 18 } 19 for(i = 0;i < N;i++)//将和保存到a1[]中 20 { 21 a1[i]=a2[i]+a1[i]; 22 if(a1[i] >= 10)// 23 { 24 a1[i]=a1[i]-10; 25 a1[i+1]++; 26 } 27 } 28 } 29 int main() 30 { 31 int T,i,count; 32 scanf("%d",&T); 33 { 34 while(T--) 35 { 36 count = 0; 37 memset(a1,0,sizeof(a1)); 38 while(scanf("%s",s)!=EOF)//输入字符串 39 { 40 count ++; 41 if(s[0] =='0')//碰到字符零就跳出循环,即输入0时不再处理 42 break; 43 44 add(s,a1);//传入char型数组名和Int型数组名 45 } 46 if(count ==1) 47 printf("0 "); 48 for(i = N -1;i>=0;i--) 49 {if(a1[i]) 50 break;} 51 52 53 for(;i>=0;i--) 54 { 55 printf("%d",a1[i]); 56 } 57 58 59 printf(" "); 60 61 if(T != 0) 62 { 63 printf(" "); 64 } 65 } 66 67 } 68 }