#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
void f(int *x1,int *x2,int *out,int count );
int main()
{
int x1[99]={0}, x2[99]={0},out[99],i=0,i2=0,count;
//int *list;
char temp[99],c;
cout<<"Enter the first number:"<<endl; //get 1st number
while(i<99&&(c=getchar())!='\n')
{
temp=c;
i++;
}
i--;
int ii=i;
for(int c=0;c<=i;c++) //convert 1st number from char to int
{
x1[c]=temp[ii]-48;
ii--;
}
ii=i;
cout<<"First number: ";
for(;ii>=0;ii--)
cout<<x1[ii];
cout<<endl;
cout<<"Enter the second number:"<<endl; //get 2nd number
while(i2<99&&(c=getchar())!='\n')
{
temp[i2]=c;
i2++;
}
i2--;
ii=i2;
for(int c=0;c<=i2;c++) //convert 2nd number from char to int
{
x2[c]=temp[ii]-48;
ii--;
}
ii=i2;
cout<<"Second number: ";
for(;ii>=0;ii--)
cout<<x2[ii];
cout<<endl;
count=(i>i2)?i:i2;
f(x1,x2,out,count);
cout<<"Result:"<<endl;
for(;count>=0;count--)
cout<<out[count];
return 0;
}
void f(int *x1,int *x2,int *out,int count )
{ // int out[100];
int ex=0, temp2, temp3,ii; //define some vars for temporary number and the extra
for(ii=0;ii<=count;ii++) //+ the arrays
{
temp2=(x1[ii]+x2[ii]);
temp2+=ex;
if(temp2<10)
out[ii]=temp2;
else
{
temp3=(temp2/10);
ex=temp3;
temp3*=10;
out[ii]=(temp2-temp3);
}
}
}