**New course!**Every coder should learn

**Generative AI!**

- 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.

10 Answers

+ 4

idownvotedbecau.se/nocode

+ 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 ...

+ 2

Ipang well. he said to use recursive procedure. i tried doing what he had given aand it gave an segmentation error

+ 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.

+ 1

your question is now my property

+ 1

Coding Kitty,
Let's wait for OP's confirmation, and hopefully a tryout code.

+ 1

Ipang sorry, I was wrong. multiply two numbers with the addition concept that I entered.

+ 1

Ipang I haven't used that yet, I'm still using for: '(

0

Hi Puspa,
Are you using array to do this? cause my idea is only based on the use of an array for this.

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