C++ Program To Find Even and Odd Numbers in A Given Range

Even Numbers : Any digit or number which can be divided by 2 or groups of 2 are called as even numbers. 
Numbers like 0 , 2 , 4 , 6 , 8 , 10 , 12 , 16 ...

Odd Numbers   : Numbers other than even numbers are called as odd numbers.
Numbers like 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 ...

Algorithm:
Need to check which numbers are divided by 2 for even odd numbers for a given range indicated by the user.

Read these articles:


Program Code:

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{

  int min , max ;
  char redo;

  cout<<"*************************************************************"<<endl;
  cout<<"           Even or Odd  Numbers In a Given Range             "<<endl;
  cout<<"*************************************************************"<<endl<<endl;

 do
 {

    cout<<"Enter Range Frome minimum To maximum "<<endl<<endl;
    cout<<"Mininum value in a range =  ";
    cin>>min;
    cout<<endl;
    cout<<"Maximum value in a range =  ";
    cin>>max;
    cout<<endl;
 
    cout<<"Even Numbers In Given Range :"<<endl;
     
    for(int i = min ; i <= max ; i++)
    {
 
        if(i % 2 == 0)
        cout<<" "<< i ;
     
    }
 
    cout<<endl<<endl;
    cout<< "Odd  Numbers In Given Range :"<<endl;
 
    for(int i = min ; i <= max ; i++)
    {
 
if(i % 2 != 0)
cout<< " " << i;
     

    }
 
    cout<<endl<<endl;
    cout<<"**************************************************************"<<endl<<endl;
 
    cout<<"Enter y or Y for next number  =  ";
    cin>>redo;
    cout<<endl<<endl;


  }while(redo == 'y' || redo == 'Y' );

   getch();

}

Output: After compile and run , the output will be like this

Click on Pic to Enlarge it.


Hope that you will find this helpful.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.