Skip to main content

Odd or Even Example C++ Program using Function in C++

1 min read Updated June 30, 2026
Share:
On this page (6sections)

About this program

This is an example program in c common example program. Read the concept first: C++ Variables and Data Types, then study the code and output below.

Definition

A formal definition of an even number is that it is an integer of the form n = 2k, where k is an integer;[3] it can then be shown that an odd number is an integer of the form n = 2k + 1.

Odd Or Even Example Program Using Functions

/*## Odd Or Even Example Program Using Functions In C++*/
/*## Calculation C++ Programs, Datatype C++ Programs, Basic C++ Programs*/

#include <iostream>
#include<conio.h>
#include<stdlib.h>

using namespace std;

string odd_even(int i);

int main() {
   // Declare Variables
   int number;

   cout << "Simple C++ Program : Odd Or Even Example Program Using Functions\n";

   //Read Value
   cout << "\nEnter an integer : ";
   cin>>number;

   //Call Function and Print Result
   cout << "\n\nResult : " << odd_even(number);

   getch();
   return (0);
}

string odd_even(int number) {
   if (number % 2 == 0) {
      return "YOUR NUMBER IS EVEN NUMBER";
   } else {
      return "YOUR NUMBER IS ODD NUMBER";
   }
}

Sample Output

Simple C++ Program : Odd Or Even Example Program Using Functions

Enter an integer : 5

Result : YOUR NUMBER IS ODD NUMBER

---

Simple C++ Program : Odd Or Even Example Program Using Functions

Enter an integer : 6

Result : YOUR NUMBER IS EVEN NUMBER

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Odd or Even Example Program using Function, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses conditional logic, reading user input and user-defined functions, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials