>x; if (x%3==0&&x%5==0&&x%7==0) cou">

输入一个整数,判断其能否被3、5、7整除,并且输出结果

  • 格式:docx
  • 大小:11.33 KB
  • 文档页数:1

#include
using namespace std;
int main()
{
int x;
cout<<"请输入一个整数:\n";
cin>>x;
if (x%3==0&&x%5==0&&x%7==0)
cout<<"能同时被3、5、7整除"<else if (x%3==0&&x%5==0)
cout<<"能被3和5整除"<else if (x%3==0&&x%7==0)
cout<<"能被3和7整除"<else if (x%5==0&&x%7==0)
cout<<"能被5和7整除"<else if (x%3==0)
cout<<"能被3整除"<else if (x%5==0)
cout<<"能被5整除"<else if (x%7==0)
cout<<"能被7整除"<else
cout<<"不能被3、5、7任一个整除"<}