80. Write a program to add two numbers using recursive function?

#include<iostream.h>
#include<conio.h>
int x;
int add(int i)
{
                if(i==0)
                                {
                                return x;
                                }
                else
                                {
                                return(1+add(i-1));
                                }
}
void main()
{
                int a,b,c;
                clrscr();
                cout<<"Enter Two Number : \n";
                cin>>a>>b;
                x=a;
                c=add(b);
                cout<<"The Addition of "<<a<<" and "<<b<<" = "<<c<<endl;
                getch();
}

80.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: