#include <stdio.h> #include <stdlib.h> #define N 200//计算的位数 char *ADD(char *s1,char *s2) { char *resault,c,c1,c2,i=0,j=0,k=0,mark[N+1]={0}; while(*(s1+i)!=0) { if(*(s1+i)>'9' || *(s1+i)< '0') return NULL; i++; } while(*(s2+j)!=0) { if(*(s2+j)>'9' || *(s2+j)< '0') return NULL; j++; } resault=(char *)calloc(N,sizeof(char)); k=(i>j?i:j)+1; while(k!=0) { i--;j--;k--; c1=(i>=0)?(*(s1+i)-'0'):0; c2=(j>=0)?(*(s2+j)-'0'):0; c=c1+c2; if(c<10) mark[k-1]=0; else { c-=10; mark[k-1]=1; } resault[k]='0'+c+mark[k]; } return (resault[0]-'0')?resault:resault+1; } int main(void) { char str1[]="22222222222222222",str2[]="33333333333333333",*str; str=ADD(str1,str2); printf(" %24s/n",str1); printf("+%24s/n",str2); printf("=%24s/n",str); getchar(); return 0; }