不正经题解 | 判断整除
2024-08-04 18:44:06
发布于:浙江
温馨提示
该贴为双语言贴,下方有英文版。
Warm reminder
This post is bilingual, with an English version below.
思路分析
根据题意,我们可以知道其实这一道题实际上就是让我们求出这个数是不是3或5的倍数。我们可以直接通过%来求出是否是等于0,也可以通过创建一个dable类型的变量,算出n分别取除以3和5的数值,在通过%1,和dable变量的储存来判断他是否是3和5的整数。
答案
#include <iostream>
using namespace std;
bool daan(int n){
if(n % 3 == 0 && n % 5 == 0)
return true;
else
return false;
}
int main(){
int n;
cin >> n;
if(daan(n))
cout << "YES";
else
cout << "NO";
return 0;
}
答案讲解
在这里呢,我运用到了函数,通过函数来判断是否是3或5的倍数,如果满足要求则返回true,不满足返回false,在通过if的判断来输出
如果是true,则输出“YES”
否则输出“NO”
**时间
我们的工作室应为一个小小小小的以外掉了80多个人,我代表全室来发送招募,大家感兴趣的可以来加入哦!一天内比有结果,通过的概率很大哦!
传送门
提问时间
- 这里呢为大家的提问环节,大街可以把自己的疑惑发表,我将进行审阅,并放在此处,当然,我们都可以进行解答哦。
- 要注意一下格式,格式为:
我有一个问题:
名字:
问题:
最后呢,希望大家给个小赞,谢谢。
Train of thought analysis
According to the meaning of the question, we can know that this question is actually asking us to find out if this number is * multiple of 3 or 5. We can directly use% to determine whether it is equal to 0, or we can create * variable of type dab and calculate n by dividing it by 3 and 5, and then use the storage of% 1 and dab variables to determine whether it is an integer of 3 and 5.
Answer:
#include <iostream>
using namespace std;
bool daan(int n){
if(n % 3 == 0 && n % 5 == 0)
return true;
else
return false;
}
int main(){
int n;
cin >> n;
if(daan(n))
cout << "YES";
else
cout << "NO";
return 0;
}
Answer explanation
Here, I applied * function to determine whether it is * multiple of 3 or 5. If it meets the requirements, it returns true; if it does not, it returns false. The output is determined by the if function
If true, output 'YES'
Otherwise, output 'NO'
Advertising Time
Our studio has lost over 80 people due to * small incident. On behalf of the entire studio, I am sending * recruitment message. If you are interested, you can join us! There is * high probability of success within * day!
[Portal]( https://www.acgo.cn/application/1786225240849158144 )
Question time
Here is the Q& session for everyone. The street can express their doubts, and I will review them and put them here. Of course, we can all provide answers.
*Please pay attention to the format, which is:
I have * problem:
name:
Question:
Finally, I hope everyone can give me * small thumbs up. Thank you.
全部评论 5
看懂了吗,哥们儿
2024-09-02 来自 北京
0what?
2024-09-03 来自 浙江
0
顶
2024-08-04 来自 浙江
0顶
2024-08-04 来自 浙江
0顶
2024-08-04 来自 浙江
0顶
2024-08-04 来自 浙江
0
有帮助,赞一个