#include<iostream.h>
#include<conio.h>
class recursive
{
public:
                int add(int p,int q)
                                {
                                if((p%2==0) && (p<=q))
                                                {
                                                return (p+add(p+1,q));
                                                }
                                else if(p>q)
                                                {
                                                return 0;
                                                }
                                else
                                                {
                                                return (add(p+1,q));
                                                }
                                }
};
void main()
{
                int a,b,sum;
                recursive r;
                clrscr();
                cout<<"Enter First Number :- ";
                cin>>a;
                cout<<"Enter Second Number :- ";
                cin>>b;
                sum=r.add(a,b);
                cout<<"Sum = "<<sum;
                getch();
}

156.PNG

Advertisements