Find elements

C++ program to check odd or even using recursion

C++ program to check odd or even using recursion

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

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

check odd or even using recursion

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 C++ programming operators to find odd or even number in a given number

 

C++ program to check odd or even using recursion

Program 1

This program allows the user to enter a number and is used to check whether the given number is odd or even using recursion

#include <iostream>
#include <conio.h>
using namespace std;
int isEven(int);//Function prototype/ declaration
int main()
{
    int num;  
//declare a variable num
    cout << "Enter a number to find odd or even" << endl;
    cin>>num;  
//Take input from the user and stored in variable num
    if(isEven(num)){
     cout<<"It is a even number";
}
else{
     cout<<"It is a odd number";
}
cout<<endl;
getch();
    return 0;

}


int isEven(int num)//recursive function in C++
{ //function definition or function body
if(num==0){
         return 1;
}
else if(num==1){
         return 0;
}
else if(num<0){
         return isEven(-num);
}
else
return isEven(num-2);
}

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

case 1

Enter ta number to find odd or even
345
it is a odd number

 

case 2

Enter ta number to find odd or even
456
it is a even number

 

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

 

Suggested for you

Recursion in C++ language

If statements in C++ language

Operator in C++ language

C program to check odd or even using recursion
Python program to check odd or even 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.

View Comments

  • Hello and thanks for your help. May you suggest a way how to make a c++ program that allows you to input numbers from 1 to 10, and checks which ones of them are odd, please?

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago