+ 1

What is wrong in the following code?

add of natural numbers using function https://code.sololearn.com/cU9UG4G4yoQy/?ref=app

19th Nov 2018, 12:40 PM
Abhay
Abhay - avatar
6 Respuestas
+ 3
A few minor things. The error messages tell it by the way. It is a good exercise to debug the code yourself ;) However I will tell you what is wrong: - use int instead if void for main (and return 0 at the end, that's optional though) - missing comma , in scanf function - return statement in natural function should come after the loop, not inside it. Otherwise it will return after the first iteration
19th Nov 2018, 1:07 PM
Matthias
Matthias - avatar
19th Nov 2018, 1:07 PM
Madhav
Madhav - avatar
+ 2
for the recursive approach: return 0 Or test for s!=1, then you can return 1
20th Nov 2018, 12:24 PM
Matthias
Matthias - avatar
0
thks Matthias ,but I deleted that and did using recursive function and this one is showing some bugs,can you help pls!
19th Nov 2018, 2:28 PM
Abhay
Abhay - avatar
0
no need,ty just
19th Nov 2018, 2:33 PM
Abhay
Abhay - avatar
0
ty:-)
11th Dec 2018, 7:57 PM
Abhay
Abhay - avatar