175k views
0 votes
Write a C program to check whether an input number is a multiple of only 5 (e.g. 5, 10, 15, ...), only 11 (e.g. 11, 22, 33, ...), both 5 and 11 (e.g. 55, 110, ....), or neither of them (e.g. 2,3, 4, 6, 7, 8, 9, 12, ....).

User Jossy
by
8.0k points

1 Answer

1 vote

Final answer:

The provided C program takes a numerical input and determines whether it is a multiple of only 5, only 11, both 5 and 11, or neither by using the modulus operator and conditional statements.

Step-by-step explanation:

The C program below checks whether an input number is a multiple of only 5, only 11, both 5 and 11, or neither.

#include
int main() {
int number;
printf("Enter a number: ");
scanf("%d", &number);
if (number % 5 == 0 && number % 11 == 0) {
printf("The number is a multiple of both 5 and 11\\");
} else if (number % 5 == 0) {
printf("The number is a multiple of 5 only\\");
} else if (number % 11 == 0) {
printf("The number is a multiple of 11 only\\");
} else {
printf("The number is neither a multiple of 5 nor 11\\");
}
return 0;
}

This code snippet first includes the standard input/output library with #include , then defines the main function where it asks the user for an input. It uses the modulus operator % to determine the multiple of 5 and 11. Finally, it prints the result based on the condition that is satisfied.

User Ransh
by
7.7k points