#include <iostream>
using namespace std;
int main()
{
int n;
cout << "\nInput amount of digits in a number: ";
cin >> n;
int* A=new int[n];
int* B = new int[n];
cout << "\nInput number A by digits (" << n << "digits) :";
for (int i = 0; i < n; i++)
cin >> A[i]; //input number A
cout << "\nInput number B by digits (" << n << "digits) :";
for (int i = 0; i < n; i++)
cin >> B[i]; //input number B
cout << "\nSum of numbers A and B: ";
for (int i = n - 1; i > 0; i--)
{ //sum of first n-1 digits
cout << endl << (A[i] + B[i]) % 10;
A[i - 1] += (A[i] + B[i])/10;
}
//sum of two the most significant numbers
cout << endl << (A[0] + B[0]) % 10<<endl<< (A[0] + B[0]) / 10;
//memory clearing
delete[]A;
delete[]B;
}
Comments
Leave a comment