Ctrinhcon1
/* Ltrinh ham thuc hien
-Nhap danhs ach N (N<=100)thi sinh gom ho ten,nam sinh,tong diem
-Sap xep theo tong diem giam dan
-Hien danhs ach theo hang,cot
-Tinh diem trung binh cua tat ca cac thi sinh */
#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct TS
{ char ht[25];
int ns;
float td;
};
TS a[100],tg;
int n,i,j;
float tong;
void nhap()
{ printf("Nhap n: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("
Ho ten:");
fflush(stdin);
gets(a[i].ht);
printf("Nam sinh:");
scanf("%d",a[i].ns);
printf("Diem thi:");
scanf("%f",&a[i].td);
}
}
void sapxep()
{ for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i].td<a[j].td)
{tg=a[i];
a[i]=a[j];
a[j]=tg;
}
}
void hien()
{ printf("Danh sach thi sinh la:");
for(i=0;i<n;i++)
printf("
%25s %10d %10.2f",a[i].ht,a[i].ns,a[i].td);
}
void dtb()
{ for(tong=0,i=0;i<n;i++)
tong+=a[i].td;
printf("
Trung binh diem:%f ",tong/n);
}
void main()
{ clrscr();
nhap();
sapxep();
hien();
dtb();
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top