- 5

how to calculate the sum of numbers using the rec procedure

I created a program using the Recursive procedure to calculate the sum of two numbers, but when I use variables a and b when a = 2 and b = 3 then the result is not 6.

16th Apr 2021, 6:24 AM
Puspa Sari
Puspa Sari - avatar
10 Answers
+ 4
idownvotedbecau.se/nocode
16th Apr 2021, 6:30 AM
Ananiya Jemberu
Ananiya Jemberu - avatar
+ 2
I don't understand ... You said the code was supposed to "sum two numbers". So let <a> be 2, and <b> be 3, Now you add the two, obviously you should get 5 rather than 6. Except if you meant to multiply ...
16th Apr 2021, 6:41 AM
Ipang
+ 2
Ipang well. he said to use recursive procedure. i tried doing what he had given aand it gave an segmentation error
16th Apr 2021, 6:49 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 2
Coding Kitty You probably didn't have a base case in whatever you were doing (I don't how you can add 2 numbers using recursion, 3 or more I can understand). No base case means infinite recursion, means stack overflow, means segmentation fault.
16th Apr 2021, 7:11 AM
XXX
XXX - avatar
+ 1
your question is now my property
16th Apr 2021, 6:37 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 1
Coding Kitty, Let's wait for OP's confirmation, and hopefully a tryout code.
16th Apr 2021, 7:00 AM
Ipang
+ 1
Ipang sorry, I was wrong. multiply two numbers with the addition concept that I entered.
16th Apr 2021, 9:34 AM
Puspa Sari
Puspa Sari - avatar
+ 1
Ipang I haven't used that yet, I'm still using for: '(
16th Apr 2021, 4:52 PM
Puspa Sari
Puspa Sari - avatar
0
Hi Puspa, Are you using array to do this? cause my idea is only based on the use of an array for this.
16th Apr 2021, 12:52 PM
Ipang
0
Puspa Sari, In case you haven't gotten it figured out, this one gives an example without use of array. https://www.studytonight.com/c/programs/recursion/adding-two-numbers-using-recursion
16th Apr 2021, 9:41 PM
Ipang