Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add two numbers as a string

Tags:

c

string

I have to read from standard input two numbers as strings, in C. How can I print their sum as a string too? I have:

char a[10],b[10];
printf("enter the two numbers");
scanf("%s%s",&a,&b);
char sum[20];
sum=?

A little tip,please? Thank you!

like image 577
Viva Avatar asked Feb 17 '23 13:02

Viva


1 Answers

Just do it like in elementary school

Let's say the input was "...69 + ...63"

9 + 3     = 2 and 1 to go
6 + 6 + 1 = 3 and 1 to go
...
like image 171
pmg Avatar answered Feb 20 '23 20:02

pmg