You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
1.9 KiB
152 lines
1.9 KiB
1 year ago
|
#include <stdio.h>
|
||
|
int s=3;
|
||
|
int main()
|
||
|
{
|
||
|
void log();
|
||
|
log();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void log()
|
||
|
{
|
||
|
float sum(float a[][6]);
|
||
|
void sort(float a[][6]);
|
||
|
float student[4][6];
|
||
|
int i,j;
|
||
|
student[0][0]=10001;
|
||
|
student[0][1]=11;
|
||
|
student[0][2]=99.5;
|
||
|
student[0][3]=88.5;
|
||
|
student[0][4]=89.5;
|
||
|
student[1][0]=10002;
|
||
|
student[1][1]=12;
|
||
|
student[1][2]=77.9;
|
||
|
student[1][3]=56.5;
|
||
|
student[1][4]=87.5;
|
||
|
student[2][0]=10003;
|
||
|
student[2][1]=11;
|
||
|
student[2][2]=92.5;
|
||
|
student[2][3]=99.5;
|
||
|
student[2][4]=60.5;
|
||
|
for(j=0;j<5;j++)
|
||
|
{
|
||
|
scanf("%f",&student[3][j]);
|
||
|
}
|
||
|
sum(student);
|
||
|
sort(student);
|
||
|
for(i=0;i<4;i++)
|
||
|
{
|
||
|
for(j=0;j<5;j++)
|
||
|
{
|
||
|
if(j<2)
|
||
|
{
|
||
|
printf("%g",student[i][j]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("%4.1f",student[i][j]);
|
||
|
}
|
||
|
if(j==4)
|
||
|
{
|
||
|
if(i==s)
|
||
|
{
|
||
|
printf(" inserted");
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf(" ");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
float sum(float a[][6])
|
||
|
{
|
||
|
int i;
|
||
|
for(i=0;i<4;i++)
|
||
|
{
|
||
|
a[i][5]=a[i][2]+a[i][3]+a[i][4];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void sort(float a[][6])
|
||
|
{
|
||
|
void swap(float a[][6],int x,int y);
|
||
|
void sort2(float a[][6],int n,int m);
|
||
|
int i,j,k;
|
||
|
int min;
|
||
|
for(i=0;i<4;i++)
|
||
|
{
|
||
|
min=a[i][1];
|
||
|
k=i;
|
||
|
for(j=i;j<4;j++)
|
||
|
{
|
||
|
if(min>a[j][1])
|
||
|
{
|
||
|
min=a[j][1];
|
||
|
k=j;
|
||
|
}
|
||
|
}
|
||
|
swap(a,i,k);
|
||
|
}
|
||
|
k=1;
|
||
|
j=0;
|
||
|
for(i=0;i<4;i++)
|
||
|
{
|
||
|
if(a[i][1]==a[i+1][1])
|
||
|
{
|
||
|
k++;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sort2(a,k,j);
|
||
|
j=j+k;
|
||
|
k=1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void sort2(float a[][6],int n,int m)
|
||
|
{
|
||
|
void swap(float a[][6],int x,int y);
|
||
|
int i,j,k;
|
||
|
int max;
|
||
|
for(i=m;i<m+n;i++)
|
||
|
{
|
||
|
max=a[i][5];
|
||
|
k=i;
|
||
|
for(j=i;j<m+n;j++)
|
||
|
{
|
||
|
if(max<a[j][5])
|
||
|
{
|
||
|
max=a[j][5];
|
||
|
k=j;
|
||
|
}
|
||
|
}
|
||
|
swap(a,i,k);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void swap(float a[][6],int x,int y)
|
||
|
{
|
||
|
int i;
|
||
|
float temp;
|
||
|
if(x==s)
|
||
|
{
|
||
|
s=y;
|
||
|
}
|
||
|
if(y==s)
|
||
|
{
|
||
|
s=x;
|
||
|
}
|
||
|
for(i=0;i<6;i++)
|
||
|
{
|
||
|
temp=a[x][i];
|
||
|
a[x][i]=a[y][i];
|
||
|
a[y][i]=temp;
|
||
|
}
|
||
|
}
|
||
|
|