C++ if-else (Decision Making) | Practice | GeeksforGeeks

Given an integer N. Your task is to check if the integer is greater than, less than or equal to 5.
If the integer is greater than 5, then print "Greater than 5" (without quotes).
If the integer is less than 5, then print "Less than 5".
If the integer is equal to 5, then print "Equal to 5".
 
Example 1:
Input:
N = 8
Output:
Greater than 5

 
Example 2:
Input:
N = 4
Output:
Less than 5

 
Your Task:
You don't need to read input or print anything. Your task is to complete the function compareFive() which takes the number N and returns "Greater than 5" if the integer is greater than 5 or "Less than 5" if the integer is less than 5 otherwise print "Equal to 5" if the integer equals to 5.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 100000
 
0
sourabhy12626 days ago
For C++
#include<iostream>using namespace std;
int main(){      int number;   cout<<"Enter the number is"<<endl;   cin>>number;      if(number > 5){       cout<<"Greater than 5" <<endl;   }else if(number < 5){       cout<<"Smaller than 5" <<endl;   }else if(number = 5){       cout<<"Equal to 5"<<endl;   }   return 0;}
0
mehereanuj5702 weeks ago
string compareFive(int n){       // code here        if(n<5)       {           return "Less than 5";       }       else if(n==5)       {           return "Equal to 5";       }       else       {           return "Greater than 5";       }   }
+1
harshsainilcw3 weeks ago
#include<iostream>
using namespace std;
int main()
{
  int N;
  cin>>N;
  if(N<5)
  cout<<"N is smaller then 5";
  else if(N>5)
  cout<<“N is greater then 5”;
  else 
  cout<<"N is equal to 5";
}
0
shaunak5424
This comment was deleted.
0
janvisahotra174 weeks ago
// { Driver Code Starts#include<bits/stdc++.h> using namespace std;
// } Driver Code Ends#include<iostream>Using namespace std;
int main()
// { Driver Code Starts.int main() {    int t;   cin>>t;   while(t--)   {       int N;       cin >> N;       Solution ob;       cout << ob.compareFive(N) << endl;   }   return 0; }  
0
saurabhsingh16b1 month ago
#include<iostream>
using namespace std;
int main()
{
int N;
cout<<"Enter a number"<<endl;
cin>>N;
if(N>5){
cout<<"Greater than 5"<<endl;
}
else if(N<5){
cout<<"Less than 5"<<endl;
}
else{
cout<<"Equal to 5"<<endl;
}
}
0
as52448391 month ago
int main(){   int N;   cin>>N;      if (N>5){       cout<<"Greater than 5";   }else if(5<N){       cout<<"less than 5";   }else if (N=5){       cout<<"5";   }}
0
0niharika22 months ago
if(n>5)       cout<<"Greater than 5";       else if(n<5)           cout<<"Less than 5";       else           cout<<"Equal to 5";
0
shaghayeghm6282 months ago
// { Driver Code Starts#include<bits/stdc++.h> using namespace std;
// } Driver Code Endsclass Solution{   public:   string compareFive(int n){       // code here    }};
// { Driver Code Starts.int main() {    int t;   cin>>t;   while(t--)   {       int N;       cin >> N;       Solution ob;       cout << ob.compareFive(N) << endl;   }   return 0; }  // } Driver Code Ends
0
chhavinderjeetsinghec21b728
This comment was deleted.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.