C++ Program/Code to print all the odd numbers between 1-n;

Leave a Comment
//The following C++ program code will print all the odd number between 1 to n, where n is the user //specified number

#include<iostream>             //For Input/Output Stream
#include<conio.h>               //For clrscr & getche
using namespace std;          //using the standard namespace
void main()
{
clrscr();                                //clearing the console screen
int n,i=1;                              //variable 'i' is initialized here
cout<<"Enter max. limit to which you like to print odd number:";
cin>>n;                                //input of value of  'n' from user
while(i<=n)
{
cout<<i<<",";                    //printing the no. and introducing ',' between them
i+=2;                                   //generating the next odd no. and its equivalent to 'i=i+2'
}
getche();                             //to exit the program after a keystroke
}

0 comments: