-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifelse.cpp
More file actions
51 lines (49 loc) · 1.36 KB
/
Copy pathifelse.cpp
File metadata and controls
51 lines (49 loc) · 1.36 KB
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
/*Problem statement
Programming languages have some conditional / decision-making statements that execute when some specific condition is fulfilled.
If-else is one of the ways to implement them.
You are given two numbers 'a' and 'b'.
Compare the numbers and print the relation.
Print “smaller”, “greater” or “equal” when ‘a’ is smaller than ‘b’, greater than ‘b’, or equal to ‘b’ respectively.
Example :
Input: ‘a’ = 5 and ‘b’ = 3
Output: greater
Explanation: Since ‘a’ (= 5) is greater than ‘b’ (= 3), we are printing “greater”.
Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1:
5 3
Sample Output 1:
greater
Explanation of sample input 1 :
Since ‘a’ (= 5) is greater than ‘b’ (= 3), we are printing “greater”.
Sample Input 2:
2 2
Sample Output 2:
equal
Explanation of sample input 2 :
Since ‘a’ (= 2) is equal to ‘b’ (= 2), we are printing “equal”.
Expected time complexity :
The expected time complexity is O(1).
Constraints :
-10 ^ 5 <= ‘a’ <= 10 ^ 5
-10 ^ 5 <= ‘b’ <= 10 ^ 5
*/
#include<iostream>
using namespace std;
string compareIfElse(int a, int b) {
// Write your code here
if(a>b){
return "greater";
}
else if(a<b){
return "smaller";
}
else{
return "equal";
}
}
int main(){
int a; int b;
cin>>a>>b;
string value= compareIfElse(a,b);
cout<<value;
}