选择题 共10道
判断题 共10道
编程题 共2道
执行以下C++代码,变量res的最终值是?
int a = 5, b = 2; double res = (double)a / b;
执行以下 C++ 代码,输入`65`后,输出结果是?
int grade; cin >> grade; if (grade >= 90) cout << "优秀"; else if (grade >= 70) cout << "良好"; else if (grade >= 60) cout << "及格"; else cout << "不及格";
以下C++代码执行后,输出结果是?
#include <iostream> using namespace std; int main() { int x = 15; if(x > 20) { cout << "A"; } else if(x > 10) { if(x % 3 == 0) cout << "B"; else cout << "C"; } else { cout << "D"; } return 0; }
以下C++代码执行后,`#`一共会输出多少次?
#include <iostream> using namespace std; int main() { for(int i=1;i<=4;i++) for(int j=1;j<=i;j++) cout << "#"; return 0; }
以下C++代码执行后,输出的结果是?
#include <iostream> using namespace std; int main() { int sum = 0; for(int i=1;i<=3;i++) for(int j=1;j<=2;j++) sum += i * j; cout << sum; return 0; }
执行以下代码,数组arr中元素的最终结果是?
#include <iostream> using namespace std; int main() { int arr[4] = {2, 4, 6, 8}; for (int i = 0; i < 4; i++) { arr[i] = arr[i] * 2; } // 输出查看结果 for (int i = 0; i < 4; i++) { cout << arr[i] << " "; } return 0; }
以下代码用于求数组中所有元素的平均值,横线处应填入的代码是?
int arr[5] = {10,20,30,40,50}; int sum = 0; for(int i=0;i<5;i++){ sum += arr[i]; } double avg = _________; cout << avg;
给定 n 个数字 a1,a2,…,an,再给定一个目标 t,请查找序列中第一次出现 t 的位置。
第一行:单个正整数 n
第二行:n 个整数 a1,a2,…,an
第三行:单个整数 t
若存在 t,输出第一次出现 t 的位置;否则输出 -1。
1≤n≤10000,1≤ai≤10000,1≤t≤10000
5 89 20 65 31 74 31
5
89 20 65 31 74
31
4
5 5 4 1 2 3 6
5 4 1 2 3
6
-1
5 25 35 35 35 35 35
25 35 35 35 35
35
2
打印一面三角型的旗子。旗面向左,其中三角形每条边有n个星号,旗子的旗杆也有 n 个星号。
例如,当 n=3 时,输出:
* *** ***** * * *
第一行:正整数 n
输出旗帜图案
1≤n≤20
3
7
* *** ***** ******* ********* *********** ************* * * * * * * *