回复 6楼 吹水佬
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
char sum(char *p1,char *p2)
{
int n1,n2,n3,a=0,b=0,i,j,s1=0,s2=0;
n1=strlen(p1);
n2=strlen(p2);
n3=((n1>n2)?n1:n2)+2;
char *s=(char *)malloc(n3);
for(i=0;i<n1;i++)
{
switch(p1[i])
{
case '0':a=0;break;
case '1':a=1;break;
case '2':a=2;break;
case '3':a=3;break;
case '4':a=4;break;
case '5':a=5;break;
case '6':a=6;break;
case '7':a=7;break;
case '8':a=8;break;
case '9':a=9;break;
}
double y1=(double)(n1-1-i);
s1=s1+a*pow(10.0,y1);
}
for(j=0;j<n2;j++)
{
switch(p2[j])
{
case '0':b=0;break;
case '1':b=1;break;
case '2':b=2;break;
case '3':b=3;break;
case '4':b=4;break;
case '5':b=5;break;
case '6':b=6;break;
case '7':b=7;break;
case '8':b=8;break;
case '9':b=9;break;
}
double y2=(double)(n2-1-j);
s2=s2+b*pow(10.0,y2);
}
sprintf(s,"%d",s2+s1);
return *s;
}
int main()
{
int n1,n2;
printf("请输入数组1长度:");
scanf("%d",&n1);
printf("请输入数组2长度:");
scanf("%d",&n2);
int n3=((n1>n2)?n1:n2)+1;
char *p1=(char *)malloc(n1);
char *p2=(char *)malloc(n2);
char *s=(char *)malloc(n3);
printf("请输入数组1:");
scanf("%s",p1);
printf("请输入数组2:");
scanf("%s",p2);
*s=sum(p1,p2);
printf("%s",s);
return 0;
}