求简便方法

B2043 判断能否被 3,5,7 整除

@[Ke_scholar](/user/413779) 你这没有结果为n的部分啊
by woshuai6 @ 2023-08-27 18:13:18


@[woshuai6](/user/1014709) 这题数据很水的,你说的情况不存在
by Ke_scholar @ 2023-08-27 18:18:55


@[woshuai6](/user/1014709) 如果觉得不稳妥的话也可以加个bool类型判断n是否被这三个数整除了
by Ke_scholar @ 2023-08-27 18:22:00


@[smart_](/user/542205) 1. ```cpp #include <cstdio> #include <iostream> int x,j = 3; int XD[3]; int main() { scanf("%d",&x); for(int i = 1;i < 4;i++) { if(x % j == 0) { XD[i] = j; printf("%d ",XD[i]); } else { XD[i] = 0; } j += 2; } if(XD[1] == XD[2]) { if(XD[2] == XD[3]) { printf("n"); } } return 0; } ``` 2. ```cpp #include <cstdio> #include <iostream> int x,i; bool p = 1; int main() { scanf("%d",&x);//输入,%d表示以32位十进制输(出)入整数 for(i = 3;i < 7;i += 2) { if(x % i == 0) { printf("%d ",i); p = 0; } } if(p = 1) { printf("n"); } return 0; } ```
by woshuai6 @ 2023-08-27 18:23:13


```cpp #include<iostream> int main(){ int a; std::cin>>a; if(a%3==0)std::cout<<3<<" "; if(a%5==0)std::cout<<5<<" "; if(a%7==0)std::cout<<"7"<<" "; } ``` 求关
by 123_cjc @ 2023-09-01 22:06:28


```c #include<iostream> using namespace std; int main(){ int x; cin>>x; if(x%3==0){ cout<<"3 "; } if(x%5==0){ cout<<"5 "; } if(x%7==0){ cout<<"7"; } if(x%3!=0&&x%5!=0&&x%7!=0){ cout<<"n"; } return 0; } ``` 难度中等偏下
by zhangshine @ 2023-09-25 09:02:29


上一页 |