Monday, 8 July 2013

Print Odd numbers from 1 to 500 in C++

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

void main()
{
    clrscr();
    int a=1 , b=500; //you can extend this range i.e b=1000
    cout<<"\n\n---------------------\n";
    cout<<" Odd Numbers \n";
    cout<<"---------------------\n\n";
    while(a<=b)
    {   
        if(a%2!=0)     
            cout<<a<<" ,";
        a++;
    }   
getche() ;
}

No comments:

Post a Comment