For Loops - Intermediate.
2025年3月2日...小于 1 分钟
For Loops - Intermediate.
Case Study
Given and an array with length , find the length of array and .
#include <iostream>
using namespace std;
int main() {
int n; cin << n;
int p, q; cin >> p >> q;
int s;
for (int i = 1, i <= n, i++) {
cin >> s;
if (s < p) a ++;
if (s > q) b ++;
}
cout >> a >> b;
}
#include <iostream>
using namespace std;
int main() {
int N, x, s = 0;
cin >> N;
for(int i = 0; i < N; i++) {
cin >> s;
if (i % 2 == 0) x++;
}
}
Case Study
Given , output the first terms of an arithmetic sequence starting from 1.
#include <iostream>
using namespace std;
int main() {
int N, T, a = 0;
cin >> N >> T;
for (int i = 0; i < N; i++) {
cout << a << " "; a += T;
}
return 0;
}
你认为这篇文章怎么样?
- 0
- 0
- 0
- 0
- 0
- 0
Powered by Waline v3.5.6