223k views
3 votes
Write an algorithm that receives three numbers from the user and prints out the maximum of the three.

User Adonis
by
8.1k points

1 Answer

4 votes

Answer:

Algorithm:

1.Create three variables a,b,c.

2.Read the value of a,b,c from user.

3.Find maximum of a & b and assign it to m.

4.Then find maximum of c & m and assign to maxx.

5.Print maxx.

Implementation In C++:

#include <bits/stdc++.h>

using namespace std;

int main()

{

// variables

int a,b,c;

cout<<"Enter three different numbers:";

// read value from user

cin>>a>>b>>c;

// maximum of a & b

int m= ( a < b ) ? b : a;

// maximum of m and c

int maxx= ( m < c ) ? c : m;

// print maximum of all three

cout<<"maximum of three number is:"<<maxx;

return 0;

}

Output:

Enter three different numbers:12 4 15

maximum of three number is:15

User Joni Jones
by
8.8k points