发布网友 发布时间:2023-09-29 01:06
共1个回答
热心网友 时间:2024-10-08 01:56
#include "stdio.h"
int main()
{
int i, j, k;
int sum1, sum2;//计算三门课总成绩,临时变量
int gradeList[][3] = {
{67, 88, 90}, //分别代表三门课
{65, 98, 90},
{67, 88, 90},
{67, 78, 90},
{67, 88, 59},
{81, 88, 90},
{67, 88, 89},
{91, 77, 90},
{67, 88, 90},
{67, 88, 90},
{49, 99, 90},
{67, 100, 90},
{67, 88, 90},
{89, 88, 90},
{67, 69, 90},
{46, 88, 90},
{67, 33, 90},
{67, 88, 90},
{85, 87, 90},
{67, 66, 90}
};//20个学生的三门课成绩列表
int *p;//用于交换子数组的临时指针变量
int *pArr[20];
for (i = 0; i < 20; ++i) {
pArr[i] = gradeList[i];
}
for (i = 0; i < 20 - 1; ++i) {
for (k = 0; k < 20 - 1 - i; ++k) {
sum1 = 0;
sum2 = 0;
for (j = 0; j < 3; ++j) {
sum1 += pArr[k][j];
sum2 += pArr[k + 1][j];
}
if (sum1 < sum2) { //交换两个子数组
p = pArr[k];
pArr[k] = pArr[k + 1];
pArr[k + 1] = p;
}
}
}
//排序前的效果
for (i = 0; i < 20; ++i) {
for (j = 0; j < 3; ++j) {
printf(" %d ", gradeList[i][j]);
}
printf(" totalgrade %d\n", gradeList[i][0] + gradeList[i][1] + gradeList[i][2]);
}
printf("\n\n\n");
//输出处理后的数组看效果
for (i = 0; i < 20; ++i) {
for (j = 0; j < 3; ++j) {
printf(" %d ", pArr[i][j]);
}
printf(" totalgrade %d\n", pArr[i][0] + pArr[i][1] + pArr[i][2]);
}
return 0;
}
已在cl编译器测试,如下图
1
2
热心网友 时间:2024-10-08 01:56
#include "stdio.h"
int main()
{
int i, j, k;
int sum1, sum2;//计算三门课总成绩,临时变量
int gradeList[][3] = {
{67, 88, 90}, //分别代表三门课
{65, 98, 90},
{67, 88, 90},
{67, 78, 90},
{67, 88, 59},
{81, 88, 90},
{67, 88, 89},
{91, 77, 90},
{67, 88, 90},
{67, 88, 90},
{49, 99, 90},
{67, 100, 90},
{67, 88, 90},
{89, 88, 90},
{67, 69, 90},
{46, 88, 90},
{67, 33, 90},
{67, 88, 90},
{85, 87, 90},
{67, 66, 90}
};//20个学生的三门课成绩列表
int *p;//用于交换子数组的临时指针变量
int *pArr[20];
for (i = 0; i < 20; ++i) {
pArr[i] = gradeList[i];
}
for (i = 0; i < 20 - 1; ++i) {
for (k = 0; k < 20 - 1 - i; ++k) {
sum1 = 0;
sum2 = 0;
for (j = 0; j < 3; ++j) {
sum1 += pArr[k][j];
sum2 += pArr[k + 1][j];
}
if (sum1 < sum2) { //交换两个子数组
p = pArr[k];
pArr[k] = pArr[k + 1];
pArr[k + 1] = p;
}
}
}
//排序前的效果
for (i = 0; i < 20; ++i) {
for (j = 0; j < 3; ++j) {
printf(" %d ", gradeList[i][j]);
}
printf(" totalgrade %d\n", gradeList[i][0] + gradeList[i][1] + gradeList[i][2]);
}
printf("\n\n\n");
//输出处理后的数组看效果
for (i = 0; i < 20; ++i) {
for (j = 0; j < 3; ++j) {
printf(" %d ", pArr[i][j]);
}
printf(" totalgrade %d\n", pArr[i][0] + pArr[i][1] + pArr[i][2]);
}
return 0;
}
已在cl编译器测试,如下图
1
2
热心网友 时间:2024-10-08 01:57
#include "stdio.h"
int main()
{
int i, j, k;
int sum1, sum2;//计算三门课总成绩,临时变量
int gradeList[][3] = {
{67, 88, 90}, //分别代表三门课
{65, 98, 90},
{67, 88, 90},
{67, 78, 90},
{67, 88, 59},
{81, 88, 90},
{67, 88, 89},
{91, 77, 90},
{67, 88, 90},
{67, 88, 90},
{49, 99, 90},
{67, 100, 90},
{67, 88, 90},
{89, 88, 90},
{67, 69, 90},
{46, 88, 90},
{67, 33, 90},
{67, 88, 90},
{85, 87, 90},
{67, 66, 90}
};//20个学生的三门课成绩列表
int *p;//用于交换子数组的临时指针变量
int *pArr[20];
for (i = 0; i < 20; ++i) {
pArr[i] = gradeList[i];
}
for (i = 0; i < 20 - 1; ++i) {
for (k = 0; k < 20 - 1 - i; ++k) {
sum1 = 0;
sum2 = 0;
for (j = 0; j < 3; ++j) {
sum1 += pArr[k][j];
sum2 += pArr[k + 1][j];
}
if (sum1 < sum2) { //交换两个子数组
p = pArr[k];
pArr[k] = pArr[k + 1];
pArr[k + 1] = p;
}
}
}
//排序前的效果
for (i = 0; i < 20; ++i) {
for (j = 0; j < 3; ++j) {
printf(" %d ", gradeList[i][j]);
}
printf(" totalgrade %d\n", gradeList[i][0] + gradeList[i][1] + gradeList[i][2]);
}
printf("\n\n\n");
//输出处理后的数组看效果
for (i = 0; i < 20; ++i) {
for (j = 0; j < 3; ++j) {
printf(" %d ", pArr[i][j]);
}
printf(" totalgrade %d\n", pArr[i][0] + pArr[i][1] + pArr[i][2]);
}
return 0;
}
已在cl编译器测试,如下图
1
2