Write a C program to check divisibility by N.
int main() {
int dividend, divisor;
/* get the dividend value from user */
printf("Enter the value for dividend:");
scanf("%d", ÷nd);
/* get the divisor value from user */
printf("Enter the value for divisor:");
scanf("%d", &divisor);
/* dividend % divisor is 0 => divisible */
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
jp@jp-VirtualBox:~/$ ./a.out
Enter the value for dividend:1235
Enter the value for divisor:23
1235 is not divisible by 23
Enter the value for dividend:100
Enter the value for divisor:10
100 is divisible by 10
jp@jp-VirtualBox:~/$ ./a.out
Enter the value for dividend:1235
Enter the value for divisor:23
1235 is not divisible by 23
No comments:
Post a Comment