Large number-Addition

Source: Internet
Author: User
Tags strlen
#include <iostream>
#include <string>
using namespace Std;


#define MAX 101
#define H 100


Char Ca[max];
Char Cb[max];
int A[max];
int B[max];
int C[max];


void output (int m,int n)
{
for (int i = 0; i < m; i++) cout << ca[i];
cout << "+";
for (int i = 0; i < n; i++) cout << cb[i];
cout << "=";
int flag = 1;
for (int i = 0; i < MAX; i++)
{
if (c[i] = = 0 && flag = = 1) continue;
Else
{
flag = 2;
cout << C[i];
}
}
}


void Big_add (int m, int n)//Extra large number of additive cores
{
int sum = H;
for (int i = H; I >= 0; i--)
{
int part1 = A[i] + b[i];
int part2 = C[sum] + part1;
C[sum] = part2% 10;
C[--sum] + = PART2/10;
}
Output (M, n);
}


int main ()
{
while (gets_s (CA), gets_s (CB))
{
/* Initialize */
memset (A, 0, sizeof (a));
memset (b, 0, sizeof (b));
memset (c, 0, sizeof (c));
/////////////////////////
int m = strlen (CA);
int n = strlen (CB);
int x = H;
for (int i = m-1; I >= 0; i--) a[x--] = ca[i]-' 0 '; To facilitate the insertion of an integer array from the end
x = H;
for (int i = n-1; I >= 0; i--) b[x--] = cb[i]-' 0 ';
Big_add (M, n);
cout << Endl;
}
return 0;
}

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.