C++ tutorial, C++ programs, C++ Exercises, C++ Example Programs

Monday, December 9, 2013

Program For Loop Display 1 To N Odd

Program to display all odd numbers between 1 and N
/*
Write a C++ Program to display All Odd numbers from
1 to n (the entered positive number greater than 1)
by FOR Loop.

For Free C++ Programming Techniques (Example Programs), visit
Www.EasyCppProgramming.Blogspot.Com

and For Good Notes
Visit   Www.ForFreeEducation.Blogspot.Com
*/
#include<iostream.h>

#include<conio.h>

void main()
{

  clrscr();

  int number, counter;

  label1:
  cout<<"\n Enter a positive number = ";

  cin>>number;

  if ( number<=1 )
  {
    cout<<"\n Please Enter a Positive Number Greater than 1";
    goto label1;
  }

  cout<<"\n\n ----------- Results ------------";

  cout<<"\n\n Display All Odd Numbers between \n 1 to n(entered positive number)\n by For Loop ";

  for (counter = 1; counter <= number; counter+=2)
           cout<<"\n \t"<<counter;

  getch();

}
Share:

0 comments:

Post a Comment

We Love To Hear From You!

EasyCPPprogramming.blogspotcom

Blog Archive

Labels