帮我出五个C语言关于数组或指针知识点的程序填空题
时间: 2024-05-02 07:19:27 浏览: 78
1. 计算数组元素和
```
int arr[5] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += _________;
}
printf("数组元素和为:%d", sum);
```
答案:arr[i]
2. 交换两个变量的值
```
int a = 5, b = 10;
int temp;
_________ = a;
a = b;
b = temp;
printf("a = %d, b = %d", a, b);
```
答案:temp = a;
3. 按升序排序数组
```
int arr[5] = {3, 1, 4, 2, 5};
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
if (arr[i] > _________) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
```
答案:arr[j]
4. 按降序排序数组
```
int arr[5] = {3, 1, 4, 2, 5};
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
if (arr[i] < _________) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
```
答案:arr[j]
5. 求数组中最大值
```
int arr[5] = {3, 1, 4, 2, 5};
int max = arr[0];
for (int i = 1; i < 5; i++) {
if (arr[i] > _________) {
max = arr[i];
}
}
printf("数组中最大值为:%d", max);
```
答案:max
阅读全文