The example below is to make a program that can decide which number is in the middle among the three numbers we have entered.
First step, make the program to ask the user to enter three numbers one by one, by cin>> syntax.
Then make the main program.
Let’s see the complete syntax below:
#include "iostream.h"
#include "conio.h"
main(){
int a,b,c;
cout<<"The Number in The Midle";
cout<<"\n=======================";
cout<<"\n\nEnter first number: ";cin>>a;
cout<<"Enter second number: ";cin>>b;
cout<<"Enter Third number: ";cin>>c;
if ((a>b && b>c)||(a< b && b< c))
cout<< "\nThe number in the midle is: "<< b;
else if ((b>c && c>a)||(b< c && c< a))
cout<< "\nThe number in the midle is: "<< c;
else if ((c>a && a>b)||(c< a && a< b))
cout<< "\nThe number in the midle is: "<< a;
else
cout<< "\nThere are the same number";
getch();
}
Run the program, the enter various number, to test whether the program run correctly or not.
These numbers shown on the picture below are enough to be samples of all kind of possibility number.
Let’s see and learn it.
0 comments:
Post a Comment