Decrement OR Increment||codechef||beginner solution ||programming info

Decrement OR Increment

Write a program to obtain a number Nand 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 

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.

SOLUTION USING C LANGUAGE:-
#include <stdio.h>
int main(void) {
    int N;
    scanf("%d",&N);
    if(N%4==0)
    N=N+1;
    else
    N=N-1;
    printf("%d",N);
	// your code goes here
	return 0;
}

Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support