int main ()
{
string str1;
string str2;
int i, j;
int size1, size2;
int Num1[21];
int Num2[21];
cout <<" enter your first number: " << endl;
cin >> str1;
cout << endl;
cout << str1 << " is your first number" << endl;
cout << "enter the second number: " << endl;
cin >> str2;
cout << endl;
cout << str2 << " is your second number" << endl;
size1=str1.size();
size2=str2.size();
for(j=0;j<=size1;j++)
{
for (i=19; i>=0; i--)
Num1[i]= str1.at(j);
}
for(j=0;j<=size2;j++)
{
for (i=19; i>=0; i--)
Num2[i]= str2.at(j);
}
}
> for example if we have array1[5]= {1,2,3,4,5}
> and array2[5]={2,3,4,0,7)
> how do you sum them up as 12345 + 23407 .
> And when i say sum I mean normal mathematical sum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <cassert>
int main()
{
constexprint N = 5 ;
constexprint a[N] = { 1, 2, 3, 4, 5 } ;
constexprint b[N] = { 2, 9, 8, 0, 7 } ;
constauto isdigit = [] ( int v ) { return v >= 0 && v < 10 ; } ;
int sum = 0 ;
for( int i = 0 ; i < N ; ++i )
{
assert( isdigit( a[i] ) && isdigit( b[i] ) ) ;
sum *= 10 ;
sum += a[i] + b[i] ;
}
std::cout << sum << '\n' ;
}