Answer to Question #272416 in C++ for tony

Question #272416

Take two positive integers a and b as input from user. Write a recursive program to print all the even numbers in range [a, b].

Sample input:

1 8

Sample output:

1 8 2 4 6 8

Sample input :

2 11

Sample output::

2 4 6 8 10


1
Expert's answer
2021-11-27T11:38:06-0500
#include <iostream>


using namespace std;


int main()
{
    int a,b;
    cout<<"Enter two positive integers: ";
    cin>>a>>b;
    if(a>0 && b>0)
    {
        cout<<"Print all the even numbers in range [a, b]"<<endl;
        for(int i=a;i<=b; i++)
        {
            if(i%2==0)
            {
             cout<<i<<endl;
            }
        }
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS