Program design of extra Large number addition C language

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.