This blog is under construction

Sunday 7 July 2013

C Program to check whether the given number N is divisible by M

Write a C program to check whether the given number N is divisible by M.


  #include <stdio.h>
  int main() {
        int dividend, divisor;

        /* get the dividend from the user */
        printf("Enter the value for dividend:");
        scanf("%d", &dividend);

        /* get the divisor from the user */
        printf("Enter the value for divisor:");
        scanf("%d", &divisor);

        /* check whether N is divisible by M */
        if (dividend % divisor == 0) {
                printf("%d is divisible by %d\n",
                        dividend, divisor);
        } else {
                printf("%d is not divisible by %d\n",
                        dividend, divisor);
        }
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the value for dividend:100
  Enter the value for divisor:10
  100 is divisible by 10





See Also:

No comments:

Post a Comment