Print Remainder when Divided by 5
Calculate and print the remainder when a given integer is divided by 5
Understand the Problem
Problem Statement
The program must accept a number and print its remainder when it is divided by 5.
For example, if the input is 12, the output should be 2 because 12 % 5 = 2.
Constraints
- The input number N is an integer
- N can be positive, negative, or zero
- Standard integer range constraints apply for the programming language used
Examples
122When 12 is divided by 5, the quotient is 2 and the remainder is 2 (since 12 = 5 × 2 + 2).
100When 10 is divided by 5, the quotient is 2 and the remainder is 0 (since 10 = 5 × 2 + 0).
72When 7 is divided by 5, the quotient is 1 and the remainder is 2 (since 7 = 5 × 1 + 2).
-32In most programming languages, -3 % 5 = 2 (since -3 = 5 × (-1) + 2).
Solution
#include <stdio.h>
int main() {
int N;
scanf("%d", &N);
printf("%d\n", N % 5);
return 0;
}Step 1: Include the standard input/output header file stdio.h
Step 2: Declare an integer variable N to store the input
Step 3: Use scanf to read the integer from standard input
Step 4: Calculate N % 5 to find the remainder
Step 5: Use printf to output the result followed by a newline
Step 6: Return 0 to indicate successful execution