Decrement OR Increment - CodeChef Solution

Decrement OR Increment - CodeChef Solution. Write a program to obtain a number N and increment its value by 1 if the number is divisible by 4.

Today we are going to solve the Decrement OR Increment CodeChef solution which mainly uses if and else statement.

So, without wasting your time let's straight away dive into the question.

Decrement OR Increment - CodeChef Solution

Task 

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 Format:

  • First line will contain a number N.

Output Format:

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

Constrains

  • 0 ≤ N ≤ 1000

Sample Input 

5

Sample Output 

4

Explanation:

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

Solution - Decrement OR Increment CodeChef Solution

Python 3 

# cook your dish here
a = int(input())
if (a % 4 == 0):
    a = a + 1
    print(int(a))
else:
    a = a - 1
    print(int(a))
Decrement OR Increment - CodeChef Solution
Decrement OR Increment - CodeChef Solution


Conclusion

I hope after going through this post, you have understand how to use if and and else statement to solve the Decrement OR Increment Problem.

The above problem is generated by CodeChef but the solution is provided by Sloth Coders. If you have any doubt regarding the problem ( Decrement OR Increment ) feel free to contact in the Comment section.

Share this post with your friends and don't forget to Subscribe our blog to get updates about coding.

Happy Coding!!

A Sloth Who loves to Code. 

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

Post a Comment