写一个c语言代码,输入若干整数作为成绩,若最后输入的是-1那就输出最小的数,-2就输出倒数第二小的数
时间: 2023-03-30 19:02:00 浏览: 88
以下是C语言代码:
```
#include <stdio.h>
int main() {
int score[100];
int i = ;
int input;
while (1) {
scanf("%d", &input);
if (input == -1) {
int min = score[];
for (int j = 1; j < i; j++) {
if (score[j] < min) {
min = score[j];
}
}
printf("最小的数是:%d\n", min);
break;
} else if (input == -2) {
int min = score[];
int secondMin = score[];
for (int j = 1; j < i; j++) {
if (score[j] < min) {
secondMin = min;
min = score[j];
} else if (score[j] < secondMin) {
secondMin = score[j];
}
}
printf("倒数第二小的数是:%d\n", secondMin);
break;
} else {
score[i] = input;
i++;
}
}
return ;
}
```
阅读全文