Find elements

C++ program to print even or odd in given range using recursion

C++ program to print even or odd in given range using recursion

In this tutorial, we will discuss a concept of the  C++ program to print odd or even number between given range using recursion

In this article, we are going to learn  how to  print of odd and even numbers using recursion in the C++ programming language

 

What is an even or odd number?

When any integer ends in 0,2,4,6,8 and it can be divided by two with the remainder of zero, it is called as an even number.

Example of even numbers – 34,-64,78,788

When any integer ends in 0,1,3,5,7,9 and it cannot be divided without a remainder, it is called as an odd number.

Example for odd numbers – 33,-69,75,785

 

Here, We can use a  C++ program operators to find odd or even number in a given range

C++ program to check odd or even using recursion

Program 1

This program allows the user to enter two input(number) for the lower limit and upper limit. and  it finds whether odd and even numbers in the given range(between upper limit to lower limit)

#include <iostream>
#include <conio.h>
using namespace std;
//function declaration
void displayEvenOdd(int num, int limit);
int main()
{
    int lowerLimit, upperLimit;
    cout<<"Enter your lower limit\n";
    cin>>lowerLimit;   //get input from user to lower limit
    cout<<"Enter your upper limit\n";
    cin>>upperLimit;    //get input from user to upper limit
    cout<<"Even/odd numbers from "<<lowerLimit<<" to "<<upperLimit<<endl;
    displayEvenOdd(lowerLimit, upperLimit);
     //function call with argument
    getch();
    return 0;
}

void displayEvenOdd(int num, int limit)//recursive function
{
    if(num>limit)
        return;
    cout<<num<<endl;

    displayEvenOdd(num + 2, limit);
}

When the above code is executed, it produces the following results

case 1

Enter your lower limit
12
Enter your upper limit
24
Even/odd numbers from 12 to 24
12
14
16
18
20
22
24

 

case 2

Enter your lower limit
11
Enter your upper limit
25
Even/odd numbers from 11 to 25
11
13
15
17
19
21
23
25

 

Similar post

Cpp program to check whether a number is even or odd

Cpp program to check  a number is even or odd using function

Cpp program to separate even and odd number from an array

Cpp program to display even and odd numbers from 1 to n

Cpp program find greatest of three numbers using function

Display odd and even numbers without if statements

Cpp program to calculate sum of odd and even numbers

Cpp program to calculate average of odd and even numbers

Cpp program to calculate average of odd and even numbers in an array

 

Suggested for you

Recursion in C++ language

If statements in C++ language

Operator in C++ language

 

 

Calculate average of odd and even numbers in Java
Program to print even or odd numbers in given range using recursion
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago