-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFA1.cpp
72 lines (71 loc) · 1.73 KB
/
FA1.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
/*Problem statement
Functions - Take this coding challenge to test your coding skills to
-define a function
-pass arguments by value to a function
-pass arguments by reference to a function
This coding challenge is organized in the following way:
First line of input reads an integer to select the coding challenge:
-Reading value '1' selects the coding-challenge 1 ( tests the ability to define a function and pass arguments by value.)
-Reading value '2' selects the coding challenge 2 (tests the ability to pass arguments by reference to a function)
Coding Challenge -1
Define a function named "Maximum" that accepts two integers (pass by value) as arguments and returns the greatest of the two arguments.
Coding Challenge -2
Define a function named "Swap" that accepts two integers (pass by reference) as arguments and swaps their value.
Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1:
1
2 3
Sample Output 1:
3
Explanation of sample input 1 :
The maximum of 2 and 3 is 3.
Sample Input 2:
2
4 5
Sample Output 2:
5 4
Explanation of sample input 2 :
The values 4 and 5 are swapped.
Expected time complexity :
The expected time complexity is O(1).
*/
#include <iostream>
using namespace std;
int Maximum(int x, int y)
{
// Write your code here.
if(x>y){
return x;
}
else{
return y;
}
}
void Swap(int &x, int &y)
{
// Write your code here.
int temp;
temp=x;
x=y;
y=temp;
}
int main()
{
int test, a, b, r;
cin >> test;
cin >> a >> b;
switch (test)
{
case 1:
r = Maximum(a, b);
cout << r;
break;
case 2:
Swap(a, b);
cout << a << " " << b;
break;
default:
cout << "Invalid test option";
}
return 0;
}