编写一个 C++ 程序,通过示例检查数字是否可被 5 和 11 整除。此 C++ 程序用于查找可被 5 和 11 整除的数字,允许我们输入任何数值。接下来,我们使用 If 语句检查给定的数字是否能被 5 和 11 整除并等于 0。根据输出,它会打印结果。
#include<iostream>
using namespace std;
int main()
{
int number;
cout << "\nEnter any Number to Check it is Divisible by 5 and 11 = ";
cin >> number;
if(( number % 5 == 0 ) && ( number % 11 == 0 ))
{
cout << "\nGiven number "<< number << " is Divisible by 5 and 11";
}
else
{
cout << "\nGiven number "<< number << " is Not Divisible by 5 and 11";
}
return 0;
}

使用条件运算符的 C++ 程序检查数字是否可被 5 和 11 整除
#include<iostream>
using namespace std;
int main()
{
int number;
cout << "\nEnter any Number to Check it is Divisible by 5 and 11 = ";
cin >> number;
((number % 5 == 0 ) && ( number % 11 == 0 )) ?
cout << "\nGiven number "<< number << " is Divisible by 5 and 11" :
cout << "\nGiven number "<< number << " is Not Divisible by 5 and 11";
return 0;
}
Enter any Number to Check it is Divisible by 5 and 11 = 75
Given number 75 is Not Divisible by 5 and 11
数字 = 55
Enter any Number to Check it is Divisible by 5 and 11 = 55
Given number 55 is Divisible by 5 and 11