/*
电子协会 C语言 1级 5 、判断能否被 3 ,5 ,7 整除
http://noi.openjudge.cn/ch0104/09/
1.4编程基础之逻辑表达式与条件分支 09判断能否被3,5,7整除(2021.05.30)
http://noi.openjudge.cn/ch0104/09/
给定一个整数,判断它能否被 3,5,7 整除,并输出以下信息:
1、能同时被 3,5,7 整除(直接输出 3 5 7,每个数中间一个空格);
2、只能被其中两个数整除(输出两个数,小的在前,大的在后。例如:3 5 或者 3 7
或者 5 7,中间用空格分隔);
3、只能被其中一个数整除(输出这个除数);
4、不能被任何数整除,输出小写字符‘n’,不包括单引号。
输入:
输入一行,包括一个整数。
输出:
输出一行,按照描述要求给出整数被 3,5,7 整除的情况。
*/
#include<iostream>
using namespace std;
int main( void )
{
int n;
cin>>n;
//------------------------------------------------
if( ( n%3 == 0 ) && (n%5==0) && (n%7==0))
{
cout<<"3 5 7";
return 0;
}
//------------------------------------------------
if( (n%3==0) && (n%5==0) )
{
cout<<"3 5";
return 0;
}
if( (n%3==0) && (n%7==0) )
{
cout<<"3 7";
return 0;
}
if( (n%5==0) && (n%7==0) )
{
cout<<"5 7";
return 0;
}
//------------------------------------------------
if(n%3==0)
{
cout<<"3";
return 0;
}
if(n%5==0)
{
cout<<"5";
return 0;
}
if(n%7==0)
{
cout<<"7";
return 0;
}
//------------------------------------------------
if( ( n%3 != 0 ) && (n%5!=0) && (n%7!=0))
{
cout<<"n";
return 0;
}
//------------------------------------------------
return 0;
}
1.4编程基础之逻辑表达式与条件分支 09判断能否被3,5,7整除
给定一个整数,判断它能否被 3,5,7 整除,并输出以下信息:
1、能同时被 3,5,7 整除(直接输出 3 5 7,每个数中间一个空格);
2、只能被其中两个数整除(输出两个数,小的在前,大的在后。例如:3 5 或者 3 7
或者 5 7,中间用空格分隔);
3、只能被其中一个数整除(输出这个除数);
4、不能被任何数整除,输出小写字符‘n’,不包括单引号。
输入:
输入一行,包括一个整数。
输出:
输出一行,按照描述要求给出整数被 3,5,7 整除的情况。
python3代码:
"""
1.4编程基础之逻辑表达式与条件分支 09 判断能否被3,5,7整除
http://noi.openjudge.cn/ch0104/09/
https://blog.csdn.net/yigezzchengxuyuan/article/details/86651658
"""
n = int(input())
if n % 3 == 0 and n % 5 == 0 and n % 7 == 0:
print(3, 5, 7, sep=' ')
elif n % 3 == 0 and n % 5 == 0:
print(3, 5, sep=' ')
elif n % 3 == 0 and n % 7 == 0:
print(3, 7,sep=' ')
elif n % 5 == 0 and n % 7 == 0:
print(5, 7,sep=' ')
elif n % 3 == 0:
print(3)
elif n % 5 == 0:
print(5)
elif n % 7 == 0:
print(7)
else:
print('n')
C++参考代码二:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
if(n%3==0)
{
printf("3 ");
}
if(n%5==0)
{
printf("5 ");
}
if(n%7==0)
{
printf("7 ");
}
if(n%3!=0 && n%5!=0 && n%7!=0)
{
printf("n\n");
}
return 0;
}
C++参考代码三:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
scanf("%d",&a);
if(a%3==0) printf("3 ");
if(a%5==0) printf("5 ");
if(a%7==0) printf("7\n");
if((a%3!=0)&&(a%5!=0)&&(a%7!=0)) printf("n\n");
system("pause");
return 0;
}
C++参考代码四:
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if( (n%3==0) && (n%5==0) && (n%7==0))
{
cout<<"3 5 7";
//return 0;
}
else
{
if( (n%3==0) && (n%5==0) )
{
cout<<"3 5";
}
else
{
if( (n%3==0) && (n%7==0) )
{
cout<<"3 7";
}
else
{
if( (n%5==0) && (n%7==0) )
{
cout<<"5 7";
}
else
{
if(n%3==0)
{
cout<<"3";
}
else
{
if(n%5==0)
{
cout<<"5";
}
else
{
if(n%7==0)
{
cout<<"7";
}
else
{
cout<<"n";
}
}
}
}
}
}
}
return 0;
}
C++参考代码五:
/*
1.4编程基础之逻辑表达式与条件分支 09判断能否被3,5,7整除(2021.05.30)
http://noi.openjudge.cn/ch0104/09/
*/
#include<iostream>
using namespace std;
int main( void )
{
int n;
cin>>n;
//------------------------------------------------
if( ( n%3 == 0 ) && (n%5==0) && (n%7==0))
{
cout<<"3 5 7";
return 0;
}
//------------------------------------------------
if( (n%3==0) && (n%5==0) )
{
cout<<"3 5";
return 0;
}
if( (n%3==0) && (n%7==0) )
{
cout<<"3 7";
return 0;
}
if( (n%5==0) && (n%7==0) )
{
cout<<"5 7";
return 0;
}
//------------------------------------------------
if(n%3==0)
{
cout<<"3";
return 0;
}
if(n%5==0)
{
cout<<"5";
return 0;
}
if(n%7==0)
{
cout<<"7";
return 0;
}
//------------------------------------------------
if( ( n%3 != 0 ) && (n%5!=0) && (n%7!=0))
{
cout<<"n";
return 0;
}
//------------------------------------------------
return 0;
}
/*
思维的体操
围棋
象棋
*/
C++参考代码六:
#include <iostream>
using namespace std;
int main(void)
{
int n;
cin >> n;
if (n % 3 == 0)
{
cout << '3';
if (n % 5 == 0)
{
cout << ' ' << '5';
if (n % 7 == 0)
{
cout << ' ' << '7' << endl;
}
}
else
{
if (n % 7 == 0)
{
cout << ' ' << '7' << endl;
}
}
}
else
{
if (n % 5 == 0)
{
cout << '5';
if (n % 7 == 0)
{
cout << ' ' << '7' << endl;
}
}
else
{
if (n % 7 == 0)
{
cout << '7' << endl;
}
else
{
cout << 'n' << endl;
}
}
}
return 0;
}
电子协会 C语言 1级 5 、判断能否被 3 ,5 ,7 整除
1.4编程基础之逻辑表达式与条件分支 09 判断能否被3,5,7整除
1.4编程基础之逻辑表达式与条件分支 09判断能否被3,5,7整除(2021.12.05)
1.4编程基础之逻辑表达式与条件分支 09判断能否被3,5,7整除(2021.12.05)_编程题 多分支判断整除_dllglvzhenfeng的博客-CSDN博客