练习二维数组代码
运行无法继续,
#include <stdio.h>
#include <stdlib.h>
#define Course 6
#define Student 4
void MaxScore(double e[][Course])
{
int temp, row, col, shift;
for (col = 0; col < Course; col++)
{
for (shift = 0; shift <= Student - 2; shift++)
{
for (row = 0; row <= Student - shift - 2; col++)
{
if (e[row][Course] >e[row + 1][Course])
{
temp = e[row][Course];
e[row][Course] = e[row + 1][Course];
e[row + 1][Course] = temp;
}
}
}
printf("\n科目%d的最高分为%d\n", col, e[Student - 1][col]);
}
}
int main()
{
int col, row;
double score[Student][Course];
for (row = 0; row < Student; row++)
{
for (col = 0; col < Course; col++)
scanf("%lf", &score[row][col]);
}
MaxScore(score);
system("pause");
return 0;
}
输入4行6列后运行窗不运行,无法继续输入,但不运行
我试了好几次都没找出来,仍在思考
希望大能能在百忙中帮忙扫一眼,不胜感激
参考如下:
void MaxScore(double e[][Course])
{
int temp, row, col;
for (col = 0; col < Course; col++)
{
for (row = 0; row < Student - 1; row++)
{
if (e[row][col] > e[row + 1][col])
{
temp = e[row][col];
e[row][col] = e[row + 1][col];
e[row + 1][col] = temp;
}
}
printf("\n科目%d的最高分为%lf\n", col + 1, e[Student - 1][col]);
}
}
如有帮助,欢迎点赞+采纳哈!
for (row = 0; row <= Student - shift - 2; col++)
最后一个是row++