Write a C Program to Check divisibility

Topics

  • The program first declares two variables num1 and num2 to store the user input.
  • It then prompts the user to enter two numbers using the printf() and scanf() functions.
  • An if-else statement is used to check whether num1 is divisible by num2 using the modulo operator %. If the remainder of num1 divided by num2 is equal to 0, the program prints that num1 is divisible by num2. Otherwise, the program prints that num1 is not divisible by num2.
  • Finally, the program returns 0 to indicate successful execution.
#include <stdio.h>

int main() {
    int num1, num2;

    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("Enter second number: ");
    scanf("%d", &num2);

    if (num1 % num2 == 0) {
        printf("%d is divisible by %d.", num1, num2);
    } else {
        printf("%d is not divisible by %d.", num1, num2);
    }

    return 0;
}

OUTPUT

Enter first number: 12
Enter second number: 3
12 is divisible by 3.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *