-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChallenge_5.cpp
76 lines (72 loc) · 2.52 KB
/
Challenge_5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
// Function prototype or deceleration
string maximum(int firstnumber, int secondnumber, int thirdnumber, int fourthnumber); // Maximum number
string minimum(int firstnumber, int secondnumber, int thirdnumber, int fourthnumber); // Minimum number
// Main Function
int main()
{
/*Write two functions to print the maximum and the minimum number respectively among four
numbers entered by the user. */
int n1, n2, n3, n4;
string resultmax, resultmin;
cout << "Enter first number: ";
cin >> n1;
cout << "Enter second number: ";
cin >> n2;
cout << "Enter third number: ";
cin >> n3;
cout << "Enter fourth number: ";
cin >> n4;
resultmax = maximum(n1, n2, n3, n4); // function called
cout << "------------------------" << endl;
cout << resultmax << endl;
cout << "------------------------" << endl;
resultmin = minimum(n1, n2, n3, n4); // function called
cout << resultmin;
}
// Function definition
// Maximum number
string maximum(int firstnumber, int secondnumber, int thirdnumber, int fourthnumber)
{
string result;
if ((firstnumber > secondnumber) && (firstnumber > thirdnumber) && (firstnumber > fourthnumber))
{
result = "Firt number is maximum then others ";
}
else if ((secondnumber > firstnumber) && (secondnumber > thirdnumber) && (secondnumber > fourthnumber))
{
result = "Second number is maximum then others ";
}
else if ((thirdnumber > firstnumber) && (thirdnumber > secondnumber) && (thirdnumber > fourthnumber))
{
result = "Third number is maximum then others ";
}
else
{
result = "Fourth number is maximum then others ";
}
return result;
}
// Mainimum number
string minimum(int firstnumber, int secondnumber, int thirdnumber, int fourthnumber)
{
string result;
if ((firstnumber < secondnumber) && (firstnumber < thirdnumber) && (firstnumber < fourthnumber))
{
result = " Firt number is minimum then others ";
}
else if ((secondnumber < firstnumber) && (secondnumber < thirdnumber) && (secondnumber < fourthnumber))
{
result = "Second number is minimum then others ";
}
else if ((thirdnumber < firstnumber) && (thirdnumber < secondnumber) && (thirdnumber < fourthnumber))
{
result = "Third number is minimum then others ";
}
else
{
result = "Fourth number is minimum then others ";
}
return result;
}