#include <stdio.h> #include <string.h>int main (Int argc, const char * argv[]) { char one[100],two[100],sum[100 ]; int temp=0,lenth,lenthtwo,i,lenthofsum; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%s", one); getchar ();//read carriage return character &NBSP;&NBSP;SCANF ("%s", and; lenthtwo = (int) strlen ( Both); if (strlen () >strlen (one)//always let one store longer strings { char stringtemp[100]; strcpy (Stringtemp, two); strcpy (Two, one); strcpy (one, stringtemp) ; } lenth = (int) (strlen (one)-strlen (one)); for (i= (int) strlen (both) -1; i>=0 ; i--) { sum[i+lenth] = two[i] + one[i+lenth ]-' 0 ' +temp; if (sum[i+lenth]>57) { sum[i +lenth] = sum[i+lenth] - 10; temp = 1; } else { temp = 0; } } for (i=lenth-1; i>=0; i--) { sum[i] = one[i]+temp; if (sum[i]> ) { sum[i] = sum[i] -10; temp = 1; } else { temp = 0; } } lenthofsum = strlen (sum); if (temp==1) {//the highest bit may be near-bit, resulting in a number longer than the length of the String one, so you need to move all the numbers back one, before adding a for (int i=0; i<lenthofsum; i++) { sum[lenthofsum-i] = sum[lenthOfsum-i-1]; } sum[0] = ' 1 '; } printf ("%s\n", sum); return 0;} Results Demo//3032832398719038781904783904783294873248783493194394132041834// 323819473948324891247129084723412348713403284//--- ----------------------------------------------------------//3032832398719039105724257853108186120377868216606742845445118
This article is from the Web Learning Summary blog, so be sure to keep this source http://8947509.blog.51cto.com/8937509/1572062
Program design of extra Large number addition C language