C++ Program to Add Two Numbers using Recursion

C++ Program to Add Two Numbers using Recursion

Write C++ Program to Add Two Numbers using Recursion

// CPP Program to Add Two Numbers using Recursion

#include <iostream>

using namespace std;

int add(int n1, int n2)
{
	int result = 0;
	if(n1 == 0)
		return n2;
	else
        result = add(n2, n1 - 1) + 1;
    return result;

}
int main()
{
	int n1,n2;

	cout << "Enter Number 1 :--> ";
	cin >> n1;

	cout << "Enter Number 2 :--> ";
	cin >> n2;

	int sum = add(n1, n2);

	cout << n1 << " + " << n2 << " = " << sum;
	return 0;

}

Output:

Enter Number 1 :--> 6
Enter Number 2 :--> 4
6 + 4 = 10