GESP2023年12月认证C++一级( 第三部分编程题(2)小杨报数)
参考程序1
#include <bits/stdc++.h>
using namespace std;int main() {int n, m;cin >> n >> m; // 读两个整数for (int i = 1; i <= n; ++i) {if (i % m != 0) { // 不是 m 的倍数就输出cout << i << '\n';}}return 0;
}
参考程序2
#include <cstdio>
int main()
{
int n, m, i;
scanf("%d%d", &n, &m);
for(i=1; i<=n; i++)
{
if(i%m!=0) printf("%d\n", i);
}
return 0;
}
参考程序3
#include <bits/stdc++.h>
using namespace std;int main() {int n, m;cin >> n >> m; // 读两个整数for (int i = 1; i <= n; ++i) {if (i % m == 0) continue; // 如果是倍数,跳过下面的输出,继续下一次循环cout << i << '\n';}return 0;
}