编写一个C语言程序,使用If Else语句和条件运算符的示例,来检查一个数字是否能被5和11整除。
C语言判断数字是否能被5和11整除的程序示例
此程序帮助用户输入任意数字。接下来,此程序使用If Else语句检查该数字是否同时能被5和11整除。
#include<stdio.h>
int main()
{
int number;
printf("\n Please Enter any Number to Check whether it is Divisible by 5 and 11 : ");
scanf("%d", &number);
if (( number % 5 == 0 ) && ( number % 11 == 0 ))
printf("\n Given number %d is Divisible by 5 and 11", number);
else
printf("\n Given number %d is Not Divisible by 5 and 11", number);
return 0;
}

使用条件运算符检查数字是否能被5和11整除的程序
这个程序将在C编程中使用条件运算符来检查它是否同时能被5和11整除。
#include<stdio.h>
int main()
{
int num;
printf("\n Please Enter any Value : ");
scanf("%d",&num);
((num % 5 == 0 ) && ( num % 11 == 0 )) ?
printf("\n %d is Divisible by 5 and 11", num) :
printf("\n %d is Not Divisible by 5 and 11", num);
return 0;
}
Please Enter any Value : 110
110 is Divisible by 5 and 11
我试试另一个值
Please Enter any Value : 205
205 is Not Divisible by 5 and 11