I want to take two string input from user in c#, and than convert them to integer by their position in array and then add them. My code is the one below.
string a = Console.ReadLine();
string b = Console.ReadLine();
int i,c,d,j;
for (i=a.Length-1;i>=0;i--)
{
c = Convert.ToInt32(a[i]);
d = Convert.ToInt32(b[i]);
j = c + d;
Console.WriteLine("{0} ",j);
Console.ReadKey();
}
This code is showing wrong output such as "99 99" for input "12 21". I wanted to add c+d then put the sum in j. Ultimately I want to write a code for big sum problem. Where I am making mistakes?
Expected: for strings "12" and "34" output to be "46" (1+3 and 2+4).