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

Tuesday, December 10, 2013

All Even Numbers Between Two Numbers Inclusive

All Even Numbers Between Two Numbers Inclusive, Program To Display All Even Numbers Between Two Numbers Inclusive

/*
Write a C++ Program to input two numbers
n1 and n2 then display All Even numbers between
these numbers (inclusive) 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 number1, number2, counter;

  cout<<"\n Enter the First Number = ";

  cin>>number1;

  cout<<"\n Enter the Second Number = ";

  cin>>number2;

   if ( number1 == number2 )
  {
      cout<<"\n Both Numbers are equal,\nso there are no numbers between them, Exiting!";
          goto label1;
  }

  if ( number1 > number2 )
  {
          int temp = number1;
          number1 = number2;
          number2=temp;
  }

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

  cout<<"\n\n All Even Numbers between \n "<<number1<<" and "<<number2<<" (inclusive)are:\n";

  for (counter = number1; counter <= number2; counter++)
           if ( counter % 2 == 0)
           cout<<"\n \t"<<counter;

  label1:
  getch();

}
Share:

0 comments:

Post a Comment

We Love To Hear From You!

EasyCPPprogramming.blogspotcom

Blog Archive

Labels