因为二维数组各行之间在内存中的存放也是连续的,故也可以当作一维数组处理。
//
// Created by louyu on 2018/12/20.
// Copyright © 2018 louyu. All rights reserved.
//
#include <stdio.h>
void print(double *p,int i)
{
int j;
for (j=0; j<5; j++)
{
printf("%.0lf",*(p+5*i+j));
if(j!=4) printf(" ");
}
printf("\n");
}
int main()
{
int i,j,sum=0;
double *p;
double score[10][5]={
80,81,83,93,90,
75,75,88,90,99,
22,57,78,21,66,
52,56,12,78,75,
35,32,85,50,98,
24,69,98,80,82,
84,41,42,75,95,
98,99,90,95,96,
60,65,70,40,20,
66,77,88,99,88
};
p=*score;
printf("排序前学生成绩为:\n");
for (i=0; i<10; i++)
{
for (j=0; j<5; j++)
{
printf("%.0lf",*(*(score+i)+j));
if(j!=4) printf(" ");
}
printf("\n");
}
double score_ave[10];
for (i=0; i<50; i++)
{
sum+=*p;
p++;
if((i+1)%5==0)
{
score_ave[(i+1)/5-1]=sum/5;
sum=0;
}
}
printf("均分从大到小排序后的成绩为:\n");
double max=score_ave[0];
int max_index=0;
for (i=0; i<10; i++)
{
for (j=1; j<10; j++)
{
if(max<score_ave[j])
{
max=score_ave[j];
max_index=j;
}
}
print(*score,max_index);
score_ave[max_index]=0;
max=score_ave[0];
max_index=0;
}
return 0;
}