大数加法,可调用
#include "stdio.h" #include "string.h" /* name:大数加法 author:YouRmyDream */ void sup_addition(char a[],char b[],char c[]) { int c1=strlen(a); int c2=strlen(b); int d,k=0,w=0; int i=c1-1,j=c2-1; while(i>=0&&j>=0) { d=a[i--]+b[j--]+k-2*'0'; k=d/10; c[w++]=d-10*k+'0'; } while(i>=0) { d=a[i--]+k-'0'; k=d/10; c[w++]=d-10*k+'0'; } while(j>=0) { d=b[j--]+k-'0'; k=d/10; c[w++]=d-10*k+'0'; } if(k) c[w]=k+'0'; c[w++]='\0'; for(i=0,j=strlen(c);i<j/2;i++) { d=c[i]; c[i]=c[j-1-i]; c[j-1-i]=d; } } int main() { char a[200],b[200],c[300]; while (~scanf("%s%s",a,b)) { sup_addition(a,b,c); puts(c); } }