Saturday, 31 October 2015

C++ Program To  Find Max Number Among Given Three Number

Problem :- Write A Program To  Find Max Number Among Given Three Number

Logic :- This Is a different logic to find max number among three number .

Step 1:- we use forth variable as 'max' and store first element in max then compare max to next to element 

Step 2 :- if second number is greater than max then store second number in max if it is less then compare with third element

Step 3 :- If third number is greater then store third element in max if condition fails then first number is greater

Solution :- 

#include<iostream>
using namespace std;
int main()
{
  int x,y,z,max;

  cout<<"Enter The Three Numbers \n";
  cin>>x>>y>>z;

  max=x;
if (y>max)
  {
  max=y;
}
if(z>max)
  {
  max=z;
}
cout<<"\nThe Greatest Number In Given Numbers "<<x<<" "<<y<<"  "<<z<<" is "<<max;

}

Output:- 

C++ Program To  Find Max Number Among Given Three Number

No comments:
Write comments

Recommended Posts × +