Header Ads Widget

Decrement OR Increment | Codechef solution

     Problem:-

Write a program to obtain a number N and increment its value by 1 if the number is divisible by 4 otherwise decrement its value by 1.

Input:

  • First line will contain a number N.

Output:

Output a single line, the new value of the number.

Constraints

  • 0N1000

Sample Input:

5

Sample Output:

4

EXPLANATION:

Since 5 is not divisible by 4 hence, its value is decreased by 1.

Code:-

#include <iostream>
using namespace std;

int main() {
int n;
cin>>n;
if(n%4==0)
cout<<n+1;
else
cout<<n-1;
    
    return 0;
}

Recommended Post:

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

Key points:-

 MCQs:-

Post a Comment

0 Comments