20200803-判断一个数能否同时被3,5,7整除(奥赛一本通 p32 9)

判断一个数能否同时被3,5,7整除,并输出以下信息:

(1)能同时被3,5,7整除(直接输出 3 5 7,每个数中间一个空格)

(2)只能被其中两个数整除(输出两个数,小的在前,大的在后,例如3 5或者3 7或者5 7,中间用空格分隔);

(3)只能被期中一个数整除(输出这个除数);

(4)不能被任何数整除,输出小写字母n,不包括引号

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,c=1;
  cin>>a;
  if(a%3==0)
  {
    cout<<"3 ";c=0;}
  if(a%5==0)
  {
    cout<<"5 ";c=0;}
  if(a%7==0){
    cout<<"7 ";c=0;}
  if(c)
    cout<<"n"<<endl;
return 0;
}

原文地址:https://www.cnblogs.com/whcsrj/p/13420107.html