Wednesday, 27 April 2016

C++ code to print all odd and even numbers in given range

In this program we will separate all the even and odd numbers in a provided range

//Code starts

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


int main(){

    int number;
    int min,max;
 
    cout << "Enter the minimum range: ";
    cin >> min;

   cout << "Enter the maximum range: ";
    cin >> max;

    cout << "Odd numbers in given range are: ";
    for(number = min;number <= max; number++)

         if(number % 2 !=0)
             cout << number<< " ";

    cout<<"\nEven numbers in given range are: ";
    for(number = min;number <= max; number++)

         if(number % 2 ==0)
             cout << number << " ";
 
    return 0;
}

//Code Ends

OUTPUT:


Share:

0 comments:

Post a Comment