Mn Sv

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Mn Sv as PDF for free.

More details

  • Words: 264
  • Pages: 3
#include"stdio.h" #include"conio.h" #include"string.h" #include"alloc.h" typedef struct pp { char hoten[28], gt; int tuoi; float d1,d2,d3; float tb; struct pp*tiep; } sinh_vien; sinh_vien *pdau; // Ham nhap danh sach sinh vien void nhap() { float t; sinh_vien *pcuoi,*pnew; pdau = pcuoi = NULL; do { pnew=(sinh_vien*)malloc(sizeof(sinh_vien)); fflush(stdin); printf("\nho ten:");gets(pnew->hoten); if(strlen(pnew->hoten)>0) { printf("gioi tinh:"); scanf("%c",&pnew->gt); printf("tuoi:"); scanf("%d",&t); pnew->tuoi=t; printf("diem toan:"); scanf("%f",&t); pnew->d1=t; printf("diem ly:"); scanf("%f",&t); pnew->d2=t; printf("diem hoa:"); scanf("%f",&t); pnew->d3=t; pnew->tb = (pnew->d1+pnew->d2+pnew->d3)/3; pnew->tiep = NULL; if( pdau==NULL ) pdau = pcuoi = pnew; else { pcuoi->tiep = pnew; pcuoi = pnew; } } } while( strlen(pnew->hoten)>0 ); free(pnew); } // Ham in thong tin ve mot sinh vien void in(sinh_vien *p) { printf("\nTen: %s Gioi tinh: %c Toan: %4.2f %4.2f",p->hoten,p->gt,p->d1,p->d2,p->d3,p->tb ); } // Ham in ra danh sach sinh vien void inds() {

Ly: %4.2f

Hoa: %4.2f

DTB:

}

sinh_vien *p=pdau; while(p) { in(p); p=p->tiep; }

// Ham in ra man hinh danh sach sinh vien co diem trung binh >=5 void intb() { sinh_vien *p=pdau; // clrscr(); printf("\n\nDanh sach sv co dtb>=5 la:"); while ( p ) { if ( p->tb>=5 ) in(p); p = p->tiep; } // getch(); } // Ham sap xep danh sach sinh vien theo diem trung binh giam dan void sapxep() { sinh_vien *p=pdau,*q,tg; // clrscr(); printf("\n\nDanh sach sinh vien xep theo diem trung binh:\n"); while(p) { q=p->tiep; while(q) { if(p->tbtb) { strcpy(tg.hoten,p->hoten);strcpy(p->hoten,q>hoten);strcpy(q->hoten,tg.hoten); tg.gt=p->gt;p->gt=q->gt;q->gt=tg.gt; tg.tuoi=p->tuoi;p->tuoi=q->tuoi;q->tuoi=tg.tuoi; tg.d1=p->d1;p->d1=q->d1;q->d1=tg.d1; tg.d2=p->d2;p->d2=q->d2;q->d2=tg.d2; tg.d3=p->d3;p->d3=q->d3;q->d3=tg.d3; tg.tb=p->tb;p->tb=q->tb;q->tb=tg.tb; } q=q->tiep; } p=p->tiep; } inds(); } void main() { clrscr(); nhap(); //

clrscr();

printf("\n\nDanh sach sinh vien xep sau khi nhap: \n"); inds(); //

}

getch(); intb(); sapxep(); getch();

Related Documents

Mn Sv
October 2019 24
Sv
June 2020 25
Sv
June 2020 32
Sv
June 2020 29
Mn
December 2019 42
Sv
June 2020 27