#include <stdio.h>
int isDivisibleByThreeAndFive(int n) {
return (n % 3 == 0 && n % 5 == 0);
}
int main() {
int num;
printf("Enter a number to check if it is divisible by both 3 and 5: ");
scanf("%d", &num);
if (isDivisibleByThreeAndFive(num)) {
printf("%d is divisible by both 3 and 5.\n", num);
} else {
printf("%d is not divisible by both 3 and 5.\n", num);
}
return 0;
}
说明:
- 定义一个函数
isDivisibleByThreeAndFive
来检查一个数是否能同时被3和5整除。 - 在
main
函数中读取一个数并调用isDivisibleByThreeAndFive
函数输出结果。