Decrement OR Increment : DECINC

                     

Decrement OR Increment Codechef Solution in C, C++ Java, and Python

Public Submission link: Click here (anyone can submit here )

CU Submission link: Click here (need login by CU account)


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

Input:

  • First line will contain a number NN.

Output:

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

Constraints

  • 0≤N≤10000≤N≤1000

Sample Input:

5

Sample Output:

4

EXPLANATION:

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

Decrement OR Increment codechef solution in C


// your code goes here
	int x;
	scanf("%d",&x);
	if(x%4==0){
	    printf("%d\n",x+1);
	    
	}
	else if(x%4!=0)
	{
	    printf("%d\n",x-1);
	}
	return 0;
}

Decrement OR Increment codechef solution in C++ 14


// your code goes here
	int n;
	cin>>n;
	
	if(n%4==0)
	cout << n+1 << endl;
	else
	cout << n-1 << endl;
	return 0;
}

Decrement OR Increment codechef solution in Python 3

n=int(input())
if n%4==0:
    print(n+1)
else:
    print(n-1)

Decrement OR Increment codechef solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int p=sc.nextInt();
		if(p%4==0)
		p+=1;
		else
		p-=1;
		System.out.println(p);
	}
}

More Codechef Solution: Click Here


* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first.

Decrement OR Increment codechef solution
Decrement OR Increment codechef solution