Thursday, April 4, 2013

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

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





#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<< " ";

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

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

OUTPUT:
Enter the minimum range: 2
Enter the maximum range: 25
Odd numbers in given range are: 3 5 7 9 11 13 15 17 19 21 23 25 
Even numbers in given range are: 2 4 6 8 10 12 14 16 18 20 22 24 


---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------


------------------------------------------------------
Searches related to C++ program to check given number is odd or even
c++ program to find whether a number is even or odd
write a c program to find the given number is even or odd
Check Odd or Even Number in C++ | Free C & C++ Programs
C++ Program to Find Even Odd number 
Learning to Program: To check whether the number is Even or Odd
even/odd program help - C++ Forum
c program to check odd or even
C++ code to get sum of all odd numbers in given range
c++ - Print out even number 
Program that prints odd numbers, even numbers and the numbers
Program that prints odd numbers form 0 to 50 (Using for Loop) 
C++ Program To Find Average Of Odd & Even Numbers
C++ program to check given number is odd or even
C++ program to print all odd numbers in given range
C++ code to print all odd and even numbers in given range
C++ code to get sum of all odd numbers in given range

4 comments:

  1. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    ReplyDelete
  2. i want help for writing this program
    Write a program that will display Write a program that will display even and odd numbers (from 1 to 30) and display there addition and display how many odd and even numbers ? Using a loop and if statement
    Example
    Even Number Odd Numbers
    2 1
    4 3
    6 5
    . .
    . 29
    30
    Addition of ODD Numbers = 240
    Addition of Even Numbers = 225
    Total ODD numbers = 15
    Total Even numbers = 15and odd numbers (from 1 to 30)

    ReplyDelete