Friday, January 31, 2014

Sum of two numbers using recursion Implemented by C++

#include<iostream.h>
int sum(int x,int y)
{
    if(y==0)
    return x;
    else
   return(sum(x+1,y-1));
}


void main()
{
    int a,b,s;
    cout<<"Enter two numbers=";
    cin>>a>>b;
    s=sum(a,b);
    cout<<endl<<"sum of two numbers="<<s;
}

No comments:

Post a Comment