Lap trinh C BT

Màu nền
Font chữ
Font size
Chiều cao dòng

Chương trình 1:tính điểm trung binh cuae n môn nhập từ bàn phím

#include <stdio.h>

#include <conio.h>

main()

{

clrscr();

int so_mon,diem,tong,i;

float diemtb;

gotoxy (2,5);

printf("hay cho biet co bao nhieu mon hoc can tinh diem trung binh:

");

scanf("%d",&so_mon);

fflush (stdin);

//kiem tra dien kin so_mon>0 va so_mon khong phai la ky tu

if (so_mon<0)

{

do

{printf("moi nhap lai so mon hoc

");

scanf("%d",&so_mon);

fflush(stdin);

}

while (so_mon<0);

}

printf("hay nhap vao so diem tung mon

");

tong=0;

//Nhap diem cho tung mon

for(i=1;i<=so_mon;i++)

{

printf("Mon%d=

",i);

scanf("%d",&diem);

fflush(stdin);

//kiem tra dieu kien diem>0 va diem khong phai la ky tu

if ((diem>10)||(diem<0))

do

{ printf("moi ban nhap lai vi diem phai nho hon 10 va lon hon 0 va khong phai la ky tu

");

printf("Mon%d=

",i);

scanf("%d",&diem);

fflush(stdin);

}

while ((diem>10)||(diem<0));

tong+=diem;

}

diemtb=tong/so_mon;

printf("diem trung binh la:%.2f",diemtb);

getch();

return 0;

}

Bài 2 :đảo vị trí số nguyên n nhập từ bàn phím

include <stdio.h>

#include <math.h>

#include <conio.h>

main()

{

float so_nguyen,so;

float a,b,c;

double so_nguyen_lam_tron,x,n;

int z,y=1,so_chu_so=1;

clrscr();

gotoxy(10,5);

printf("******************************************************************

");

gotoxy(10,6);

printf("* *

");

gotoxy(10,7);

printf("* *

");

gotoxy(10,8);

printf("* *

");

gotoxy(10,9);

printf("******************************************************************

");

gotoxy(20,7);

printf("Day la chuong trinh dao vi tri 1 so nguyen");

gotoxy(15,10);

printf("Moi ban nhap vao 1 so nguyenla:");

scanf("%f",&so_nguyen);

so_nguyen_lam_tron=ceil(so_nguyen);

n=(so_nguyen-so_nguyen_lam_tron);

//kiem tra xem co phai la 1 so nguyen hay khong

if ((n>0)||(n<0))

do { printf("So ban vua nhap khong phai la so nguyen

");

printf("Moi ban nhap lai:");

scanf("%f",&so_nguyen);

so_nguyen_lam_tron=ceil(so_nguyen);

n=abs(so_nguyen-so_nguyen_lam_tron);

}

while ((n>0)||(n<0));

//xem n co bao nhieu chu s

do { x=floor(so_nguyen_lam_tron)/pow(10,y);

x=floor(x);

y++;

so_chu_so++;

}

while (x>1);

so=so_nguyen;

//thuat toan dao so

do { b=1;

a=fmod(so_nguyen,10);

so_nguyen=(so_nguyen-a)/10;

c+=(a*pow(10,so_chu_so-1));

so_chu_so--;

b++;

}

while (so_chu_so>0);

printf("Dao cua so %.0f la so: %.0f",so,c);

getch();

return 0;

}

Bài 3:viết chương trình viết bang cửu chương gồm n cột và m hàng nè

#include <stdio.h>

#include <conio.h>

main()

{

clrscr();

gotoxy(5,2);

printf("Day la chuong trinh viet bang cuu chuong gom n cot va m hang

");

int x=7,y=10,z=9,k=10,o=9,l,a=1,i=1,colum,row,so_gach=6;

printf("So cot la:");

scanf("%d",&colum);

printf("So hang la:");

scanf("%d",&row);

for (int gach=1;gach<=((4*colum)+3);gach++)

{ gotoxy(so_gach,8);

so_gach++;

printf("-");

}

//viet ra dau I

for(int n=1;n<=(row+1);n++)

{

gotoxy(8,x);

x=x+2;

printf("I");

}

//viet ra tu 1 den m so hang cu bang cuu chuong

for (int hang=1;hang<=row;hang++)

{

gotoxy(6,z);

z=z+2;

printf("%d",hang);

}

//viet ra tu 1 den n so cot cua bang cuu chuong

for (int cot=1;cot<=colum;cot++)

{

gotoxy(y,7);

y=y+4;

printf("%d",cot);

}

//phan tinh toan trong bang cuu chuong

for (;i<=colum;i++)

{ gotoxy(k,o);

k=k+4;

l=a*i;

printf("%d",l);

if ((i>=colum)&&(o<=((2*row)+6)))

{o=o+2;

k=10;

i=0;

a++;

}

}

getch();

return 0;

}

bài 4(theo yêu cầu của Haim làm mất 4 ngày không học bài đó)

viết ra hoán vị của các số (các chữ số khác nhau từng đôi một)

#include <stdio.h>

#include <conio.h>

#include <math.h>

main()

{

double so_can_hoan_vi,so,phu;

double a,c;

double so_lam_tron,x,n,h;

long tu_so=1,den_so=9,nho=9,qwe;

int z,y=1,so_chu_so=0,t=1,e,s,k=0,qwr,hx=0,tt=1,aa=0;

int mang[10];

double mang2[10];

clrscr();

printf("day la chuong trinh hoan vi so co n chu so

");

printf(" (khac nhau tung doi 1)" );

printf("

moi nhap so can hoan vi:");

scanf("%lf:",&so_can_hoan_vi);

so_lam_tron=ceil(so_can_hoan_vi);

n=so_can_hoan_vi-so_lam_tron;

//phan kiem tra so nhap vao

//kiem tra xem co phai la 1 so nguyen hay khong

do

{ //1

phu=so_can_hoan_vi;

if (n!=0)

do{ printf("Ban vua nhap khong dung

"); //2

printf("Moi ban nhap lai:");

scanf("%lf",&so_can_hoan_vi);

so_lam_tron=floor(so_can_hoan_vi);

n=so_can_hoan_vi-so_lam_tron;

} //.1

while (n!=0);

phu=so_can_hoan_vi;

//xem n co bao nhieu chu so

do { //3

x=floor(so_lam_tron)/pow(10,y);

y++;

so_chu_so++;

} //.2

while (x>1);

s=so_chu_so;

for (int k=0;k<s;k++)

{ //4

a=fmod(so_can_hoan_vi,10);

mang[k]=a;

so_can_hoan_vi=(so_can_hoan_vi-a)/10;

}

if (s==1) {printf("so %.0lf khong co hoan vi

",phu);

e=1;

n=1;

y=1;

so_chu_so=0;

t=1;} //.3

//kiem tra xem cac chu so cua so nhap vao co giong nhau hay khong

for(int i=0;i<s-1;i++)

{

for(int d=t;d<s;d++)

{

if (mang[d]==mang[i])

{e=1;

n=1;

i=s-1;

y=1;

so_chu_so=0;

t=1;

break;}

if (d==(s-1))

{t++;

e=0;

break;}

} //.6

} //.7

} //.8

while (e!=0);

//phan chinh

printf("hoan vi la: \t");

for(int o=1;o<s;o++)

tu_so=tu_so*10;

for(int p=1;p<s;p++)

den_so=((den_so*10)+nho);

//thuat toan

for( tu_so;tu_so<den_so;tu_so++)

{

qwe=tu_so;aa=0;tt=1; //9

for(int j=0;j<s;j++)

{ h=fmod(tu_so,10);

mang2[j]=h;

tu_so=(tu_so-h)/10;

}

//kiem tra xem cac cac chu so cu tu_so co giong nhau hay khong

for(int ii=0;ii<s-1;ii++)

{

for(int dd=tt;dd<s;dd++)

{

if (mang2[dd]==mang2[ii])

{aa=s;

ii=s-1;

tt=1;

tu_so=qwe;

break;}

if (dd==(s-1))

{tt++;

break;}

}

}

for(int ht=aa;ht<s;ht++)

{ for (int hm=0;hm<s;hm++)

{ if (mang2[ht]==mang[hm])

{ hx++;

tu_so=qwe;

break;

}

if (hm==s-1)

{ ht=s;

hx=0;

tu_so=qwe;

break;

}

}

}

if ((hx==s)&&(qwe!=phu)) {printf("%ld\t",qwe);tu_so=qwe;hx=0;}

}

textcolor(RED+BLINK);

printf("

******************************

");

printf(" *Copyright by Shin *

");

printf(" * class : 08I2 *

");

printf(" * School: CIT *

");

printf(" ******************************");

getch();

return 0;

}

Còn đây là bài tập cấu trúc 1 của tui ne

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

int dem=0;

//--------struct quan ly ten cac file da luu--------------

struct quanly

{

char tenfile[30];

struct quanly *next1;

};

//------------khai bao struct ngaythang---------------

struct ngaythang

{ char ngay;

char thang;

unsigned int nam;

};

//------------khai bao struc sinhvien---------------

struct sinhvien

{

char hoten[30];

struct ngaythang ngaysinh;

char diemtoan,diemly,diemhoa;

float diemtb;

struct sinhvien *next;

};

char *filename[]={" Khong Co File Luu ",

"file1.txt","file2.txt","file3.txt","file4.txt","file5.txt",

"file6.txt","file7.txt","file8.txt","file9.txt",};

struct sinhvien *last,*first,*sv,*fileluu;//khai bao bien toan cuc

//-------------------------ham tao Menu--------------------------------

void MENU(void)

{

void Mo1(void);

void Mo2(void);

void Mo3(void);

void Mo4(void);

void Mo41(char tenkiemtra[],int oktam1);

void Mo5(void);

void Mo6(void);

void nhap(void);//khai bao prototype

char *MENU[]=

{ "* Thiet Lap Danh Sach *",

"* Xem Danh Sach *",

"* Lua Chon *",

"* Tim Kiem *",

"* Thoat *",

};

char *DS[]=

{ "* Tao Danh Sach *",

"* Them vao danh sach *",

"* Xoa Danh Sach *",

"* Quay Lai *",

};

char *InDS[]={ "* In DS SV Co Diem TB>=5 *",

"* In SV Co Diem TB Thap Nhat *",

"* In SV Co Diem TB Cao Nhat *",

"* Quay Lai *",

};

char *TK[]={ "* Theo Ten *",

"* Theo Diem Toan *",

"* Theo Diem ly *",

"* Theo Diem Hoa *",

"* Quay Lai *",

};

flag1: //thiet lap nhan"flag1"

int k, ok=-1, fl=-1,oktam1=0;

char tenkiemtra[30];

char c;

textmode(C40);//Chon che do man hinh (screen mode)

textbackground(6);//Chon mau nen (background color)

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

clrscr();

textcolor(13);

cprintf("

CHUONG TRINH QUAN LY SINH VIEN ");

gotoxy(2,6);

cprintf("*****************MENU*****************

"); //Chon mau chu (text colo

for (int t=0;t<5;t++)

{

gotoxy(2,8+2*t);

cprintf("%s",MENU[t]);

};

gotoxy(2,18);

cprintf("**************************************");

//In ten nguoi thuc hien

gotoxy(20,20);cprintf("Doan Vuong Anh Tuan");

gotoxy(20,22);cprintf("Lop:08I2");

gotoxy(40,14);

while (ok!=5)

{

if (!(c=getch())) c=getch();

textbackground(BLUE);

textcolor(13);

gotoxy(2,8+2*ok);

if(ok!=-1)

cprintf("%s",MENU[ok]);

switch (c)

{

case '\120': ok=(ok+1)%5;break;//Neu an phim MUI TEN XUONG

case '\110': ok=(ok+4)%5;break;//Neu an phim MUI TEN LEN

case '\015': ok=5;break;//Neu an phim ENTER

};

textbackground(11);

textcolor(RED);

if(ok!=-1)

{ gotoxy(2,8+2*ok);

cprintf("%s",MENU[ok]);

}

if (ok==5)

{

textmode(C80);

clrscr();

textcolor(10);

clrscr();

switch (fl) // bat dau switch

{ //-Bat dau phan"thiet lap danh sach"cua MENU------

case 0://lua chon muc "Thiet lap"

{

flag2://thiet lap nha"flag2"

int i0,k0, ok0=-1, fl0=-1;

char c0;

textmode(C40);//Chon che do man hinh (screen mode)

textbackground(6);//Chon mau nen (background color)

clrscr();

//Tao cua so voi tham so: toado, chieu dai, rong

window(5,6,46,20);

textbackground(BLUE);

clrscr();

textcolor(13);//Chon mau chu (text color)

for (i0=0;i0<4;i0++)

{

gotoxy(2,4+2*i0);

cprintf("%s",DS[i0]);

};

while (ok0!=4) //while 1

{

if (!(c0=getch())) c0=getch();

textbackground(BLUE);

textcolor(13);

gotoxy(2,4+2*ok0);

if(ok0!=-1)

cprintf("%s",DS[ok0]);

switch (c0)

{//Neu an phim MUI TEN XUONG

case '\120': ok0=(ok0+1)%4;break;

//Neu an phim MUI TEN LEN

case '\110': ok0=(ok0+3)%4;break;

case '\015': ok0=4;break;//Neu an phim ENTER

};

textbackground(11);

textcolor(RED);

if(ok0!=-1)

{ gotoxy(2,4+2*ok0);

cprintf("%s",DS[ok0]);}

if (ok0==4)

{

textmode(C80);//man hinh 80 cot

textmode(64);//man hinh 50 dong

clrscr();

textcolor(10);

clrscr();

switch (fl0)

{

case 0:nhap();goto flag2;

case 1: Mo2();goto flag2;

case 2: Mo3();goto flag2;

case 3: ok0=4;fl0=4;break;

};

if(fl0==4)

{fl=ok; goto flag1;}

if(fl0!=4) goto flag2;

}

fl0=ok0;

}; //End of While1;

}//--Het muc "thiet lap danh sach" cua MENU--

case 1: Mo1();goto flag1;

case 2: //----lua chon muc "Lua Chon"--------

{

flag4://thiet lap nha"flag4"

int i2,k2, ok2=-1, fl2=-1;

char c2;

textmode(C40);//Chon che do man hinh (screen mode)

textbackground(6);//Chon mau nen (background color)

clrscr();

window(5,6,46,20);//Tao cua so

textbackground(BLUE);

clrscr();

textcolor(13);//Chon mau chu (text color)

for (i2=0;i2<4;i2++)

{

gotoxy(2,4+2*i2);

cprintf("%s",InDS[i2]);

};

while (ok2!=4) //while 2

{

if (!(c2=getch())) c2=getch();

textbackground(BLUE);

textcolor(13);

gotoxy(2,4+2*ok2);

if(ok2!=-1)

cprintf("%s",InDS[ok2]);

switch (c2)

{

case '\120': ok2=(ok2+1)%4;break; //Neu an phim MUI TEN XUONG

case '\110': ok2=(ok2+3)%4;break; //Neu an phim MUI TEN LEN

case '\015': ok2=4;break; //Neu an phim ENTER

};

textbackground(11);

textcolor(RED);

if(ok2!=-1)

{ gotoxy(2,4+2*ok2);

cprintf("%s",InDS[ok2]);}

if (ok2==4)

{

textmode(C80);//man hinh 80 cot

textmode(64);//man hinh 50 dong

clrscr();

textcolor(10);

clrscr();

switch (fl2)

{

case 0: Mo4();

goto flag4;

case 1: Mo5();

goto flag4;

case 2: Mo6();

goto flag4;

case 3: ok2=4;fl2=4;break;

};

if (fl2==4)

{ fl=ok; goto flag1;}

if (fl2!=4) goto flag4;

}

fl2=ok2;

}; //End of While2;

}

case 3:

{

flag5://thiet lap nhan"flag5"

int i3,k3, ok3=-1, fl3=-1;

char c3;

textmode(C40);//Chon che do man hinh (screen mode)

textbackground(6);//Chon mau nen (background color)

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

clrscr();

textcolor(13);//Chon mau chu (text color)

for (i3=0;i3<5;i3++)

{

gotoxy(2,4+2*i3);

cprintf("%s",TK[i3]);

};

while (ok3!=5) //while 3

{

if (!(c3=getch())) c3=getch();

textbackground(BLUE);

textcolor(13);

gotoxy(2,4+2*ok3);

if(ok3!=-1)

cprintf("%s",TK[ok3]);

oktam1=ok3;

switch (c3)

{

case '\120': ok3=(ok3+1)%5;break; //Neu an phim MUI TEN XUONG

case '\110': ok3=(ok3+4)%5;break; //Neu an phim MUI TEN LEN

case '\015': ok3=5;break; //Neu an phim ENTER

};

textbackground(11);

textcolor(RED);

if(ok3!=-1)

{ gotoxy(2,4+2*ok3);

cprintf("%s",TK[ok3]);}

if (ok3==5)

{

textmode(C80);//man hinh 80 cot

textmode(64);//man hinh 50 dong

clrscr();

textcolor(10);

clrscr();

switch (fl3)

{

case 0: Mo41(tenkiemtra,oktam1);

goto flag5;

case 1: Mo41(tenkiemtra,oktam1);

goto flag5;

case 2: Mo41(tenkiemtra,oktam1);

goto flag5;

case 3: Mo41(tenkiemtra,oktam1);

goto flag5;

case 4: ok3=5;fl3=5;break;

};

if (fl3==5)

{ fl=ok; goto flag1;}

if (fl3!=5) goto flag5;

}

fl3=ok3;

}; //End of While3;

}//----------het muc "tim kiem"---------------------

case 4: ok=5;fl=5;break;

};//ket thuc switch

if (fl!=5) goto flag1;

}

fl=ok;

}; //End of While;

}

//-----------------------Het ham MENU----------------------

//-------------Ham luu danh sach vao 1 file ------------------------------

void luu()

{

char ten[10];

FILE *thutep,*demten;

if(dem>=10) printf("het cho luu moi xoa bot 1file");

else

{

thutep=fopen(filename[dem+1],"r");

if(thutep==NULL) dem++;

fclose(thutep);

demten=fopen("demtep.txt","w");

fprintf(demten,"%d",dem);

fclose(demten);

thutep=fopen(filename[dem],"a+");

if(thutep==NULL)

printf("

ERROR Khong the luu file");

else

{

sv=first;

while(sv!=NULL)

{

fprintf(thutep,"

Ten:%s

",sv->hoten);

fprintf(thutep,"Sinh ngay:%d-%d-%d

",sv->ngaysinh.ngay,sv->ngaysinh.thang,sv->ngaysinh.nam);

fprintf(thutep,"diem toan:%d

diemly:%d

diem hoa:%d

",sv->diemtoan,sv->diemly,sv->diemhoa);

fprintf(thutep,"diemTb:%.2f

",sv->diemtb);

sv=sv->next;

}

}

}

fclose(thutep);

}//--------het ham luu------------

//--nhap vao thong tin cua Sinh vien khi chua biet so luong sv cu the-----

void nhap(void)

{

char ten[30],chon,luachon;

float tb,tong;

first=NULL;

flushall();

do

{

printf("Moi nhap ten sinh vien(nhan enter de ket thuc):");

if (ten[0]==NULL) break;//thoat vong lap khi nhan enter

else

{

sv=(struct sinhvien *)calloc(1,sizeof(struct sinhvien));

// cap phat 1 bien dong

strcpy(sv->hoten,ten);

printf("Sinh Ngay Thang Nam(vi du 6 6 1990):

");

scanf("%d%d%d",&sv->ngaysinh.ngay,&sv->ngaysinh.thang,&sv->ngaysinh.nam);

printf("Diem Toan Ly Hoa(vi du 6 6 6):

");

scanf("%d%d%d",&sv->diemtoan,&sv->diemly,&sv->diemhoa);

tong=(sv->diemtoan+sv->diemly+sv->diemhoa);

//chuyen kieu du lieu tu int sang float de tinh diem tb

tb=tong/3;

sv->diemtb=tb;

while(getchar()!= '

'); //xoa bo nho dem

sv->next=NULL;

if (first!=NULL) last->next=sv;

else first=sv;

last=sv;

}

}

while(1); //vong lap vo han

do

{

flushall();

printf("

Ban co muon luu hay khong(C/K):");

scanf("%c",&chon);

luachon=toupper(chon);

}

while(luachon!='C'&&luachon!='K');

switch(luachon)

{ case 'C':

if(dem<=10)

{

luu();

printf(" Da luu vao file%d.txt",dem);

}

else

printf("File day(hay xoa bot 1 file de luu them)");

getch();

break;

case 'K': printf(" Ban da khong luu");break;

}

}//----------het ham nhap-------------------

//---------Ham Mo Danh Sach Da co de xem---------------------

void Mo1(void)

{

FILE *mo;

char c,t,e;

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf("%s",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if (!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break;

case '\110': ok10=(ok10+dem)%(dem+1);break;

case '\015': ok10=dem+1;break;

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

switch (thu)

{

case 0:mo=fopen(filename[oktam+1],"r");

if(mo==NULL) printf("EROOR Moi thu lai");

else{

rewind(mo);

clrscr();

do

{

putchar(c=getc(mo));

}

while(c!=-1);}

fclose(mo);

getch(); break;

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

fclose(mo);

}//------------ket thuc ham Mo1-----------------

//----Ham Mo de them vao Danh Sach Da co---------------------

void Mo2(void)

{

FILE *mo,*thutep;

char c,t,e,ten[30];

int tong,chon,luachon;

float tb;

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf(" %s ",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if(!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break;

case '\110': ok10=(ok10+dem)%(dem+1);break;

case '\015': ok10=dem+1;break;

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

switch (thu)

{

case 0:

{

mo=fopen(filename[oktam+1],"a");

if(mo==NULL) printf("EROOR Moi thu lai");

else

{

printf("Ban da chon them vao Danh sach nay.

Moi nhap so lieu

");

do

{ flushall();

printf("Moi nhap ten sinh vien(nhan enter de ket thuc):");

if (ten[0]==NULL) break;//thoat vong lap khi nhan enter

else

{

// cap phat 1 bien dong

sv=(struct sinhvien *)calloc(1,sizeof(struct sinhvien));

strcpy(sv->hoten,ten);

printf("Sinh Ngay Thang Nam(vi du 6 6 1990):

");

scanf("%d%d%d",&sv->ngaysinh.ngay,&sv->ngaysinh.thang,&sv->ngaysinh.nam);

printf("Diem Toan Ly Hoa(vi du 6 6 6):

");

scanf("%d%d%d",&sv->diemtoan,&sv->diemly,&sv->diemhoa);

tong=(sv->diemtoan+sv->diemly+sv->diemhoa);

tb=tong/3;

sv->diemtb=tb;

while(getchar()!= '

'); //xoa bo nho dem

sv->next=NULL;

if (first!=NULL) last->next=sv;

else first=sv;

last=sv;

};

}

while(1); //vong lap vo han

do

{ flushall();

printf("

Ban co muon luu hay khong(C/K):");

scanf("%c",&chon);

luachon=toupper(chon);

}

while(luachon!='C'&&luachon!='K');

switch(luachon)

{ case 'C':

flushall();

thutep=fopen(filename[oktam+1],"a");

sv=first;

while(sv!=NULL)

{

fprintf(thutep,"

Ten:%s

",sv->hoten);

fprintf(thutep,"Sinh ngay:%d-%d-%d

",sv->ngaysinh.ngay,sv->ngaysinh.thang,sv->ngaysinh.nam);

fprintf(thutep,"diem toan:%d

diemly:%d

diem hoa:%d

",sv->diemtoan,sv->diemly,sv->diemhoa);

fprintf(thutep,"diemTb:%.2f

",sv->diemtb);

sv=sv->next;

};

fclose(thutep);

printf(" Da luu them vao file nay");

getch();

break;

case 'K': printf(" Ban da khong luu");getch;break;

}

}

}//het lua chon case0

fclose(mo); break;

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

fclose(mo);

}//------------ket thuc ham Mo2-----------------

//--------------------Ham Mo Danh sach de xoa---------------------

void Mo3(void)

{

FILE *mo,*mo1,*mo2;

char c,t,e,n,chon,luachon;

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf("%s",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if (!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break;

case '\110': ok10=(ok10+dem)%(dem+1);break;

case '\015': ok10=dem+1;break;

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

switch (thu)

{

case 0:

{ flushall();

printf("

Ban co chac la muon xoa hay khong (C/K):");

scanf("%c",&chon);

luachon=toupper(chon);

}

while(luachon!='C'&&luachon!='K');

switch(luachon)

{ case 'C': remove(filename[oktam+1]);

if(dem>2&&oktam+1!=dem)

{

for(int m=oktam;m<dem-1;m++)

{ printf("

Du lieu trong %s da chuyen sang %s",filename[m+2],filename[m+1]);

mo1=fopen(filename[m+1],"w");

mo2=fopen(filename[m+2],"r");

do{

n=getc(mo2);

fprintf(mo1,"%c",n);

}

while(n!=-1);

fclose(mo1);

fclose(mo2);

remove(filename[m+2]);

};

}

printf("da xoa");

dem--;

mo=fopen("demtep.txt","w");

fprintf(mo,"%d",dem);

fclose(mo);

getch();

break;

case 'K': printf(" Ban da khong luu");break;

}

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

}

//------------ket thuc ham Mo3-----------------

//--------------------Ham Mo Danh Sach De in diem TB>=5----------------------

void Mo4(void)

{

void timkiem4(FILE *fg,char dieukien[30]);

FILE *mo;

char c,t,e;

char tenkiemtra[30];

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf("%s",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if (!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break;

case '\110': ok10=(ok10+dem)%(dem+1);break;

case '\015': ok10=dem+1;break;

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

if(oktam!=dem) strcpy(tenkiemtra,"diemTb:5.00");

switch (thu)

{

case 0:mo=fopen(filename[oktam+1],"r");

if(mo==NULL) printf("EROOR Moi thu lai");

timkiem4(mo,tenkiemtra);

break;

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

fclose(mo);

}//------------ket thuc ham Mo4-----------------

//--------------------Ham Mo Danh Sach De tim kiem theo diem,ten,diemtaon,diemly,diemhoa;----------------------

void Mo41(char tenkiemtra[],int oktam1)

{

void timkiem(FILE *fg,char dieuken[],char tentam[]);

FILE *mo;

char c,t,e,tentam[20];

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf("%s",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if (!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break; //Neu an phim MUI TEN XUONG

case '\110': ok10=(ok10+dem)%(dem+1);break; //Neu an phim MUI TEN LEN

case '\015': ok10=dem+1;break; //Neu an phim ENTER

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

switch (thu)

{

case 0:

if(oktam1==0)

{

printf("Moi nhap ten can tim:");

gets(tentam);

strcpy(tenkiemtra,"Ten:");

};

if(oktam1==1)

{

printf("Moi nhap diem toan:");

gets(tentam);

strcpy(tenkiemtra,"diem toan:");

}

if(oktam1==2)

{

printf("Moi nhap diem ly:");

gets(tentam);

strcpy(tenkiemtra,"diemly:");

}

if(oktam1==3)

{

printf("Moi nhap diem hoa:");

gets(tentam);

strcpy(tenkiemtra,"diem hoa:");

}

mo=fopen(filename[oktam+1],"r");

if(mo==NULL) printf("EROOR Moi thu lai");

timkiem(mo,tenkiemtra,tentam);

break;

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

fclose(mo);

}//------------ket thuc ham Mo41-----------------

//--------------------Ham Mo Danh Sach Da de in sv co diem thap nhat---------------------

void Mo5(void)

{

void timkiem1(FILE *fg);

FILE *mo;

char c,t,e;

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf("%s",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if (!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break; //Neu an phim MUI TEN XUONG

case '\110': ok10=(ok10+dem)%(dem+1);break; //Neu an phim MUI TEN LEN

case '\015': ok10=dem+1;break; //Neu an phim ENTER

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

switch (thu)

{

case 0:mo=fopen(filename[oktam+1],"r");

if(mo==NULL) printf("EROOR Moi thu lai");

timkiem1(mo);

break;

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

fclose(mo);

}//------------ket thuc ham Mo5-----------------

//--------------------Ham Mo Danh Sach Da de in sv co diem cao nhat---------------------

void Mo6(void)

{

void timkiem2(FILE *fg);

FILE *mo;

char c,t,e;

flag10: int k,l=0,thu,ok10=-1,fl10=-1,oktam=0;

if(dem==0)

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

gotoxy(2,4);

cprintf("%s",filename[0]);

gotoxy(2,6);

cprintf(" Quay Lai ");

textbackground(11);

textcolor(RED);

gotoxy(2,6);

cprintf(" Quay Lai ");

while(1)

{

if (!(c=getch())) c=getch();

switch (c)

{

case '\015': k=1;break;//Neu an phim ENTER

};

if(k==1) break;

}

}

else

{

textmode(C40);

textbackground(BLUE);

clrscr();

window(5,6,46,20);//Tao cua so voi tham so: toado, chieu dai, rong

textbackground(BLUE);

textcolor(13);

for(l=1;l<=dem;l++)

{

gotoxy(2,2*l);

cprintf(" %s ",filename[l]);

}

gotoxy(2,2+2*l-2);

cprintf(" Quay Lai ");

while (ok10!=dem+1)

{

if (!(e=getch())) e=getch();

if(ok10!=-1&&ok10!=dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10!=-1&&ok10==dem)

{

textbackground(BLUE);

textcolor(13);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

oktam=ok10;

switch (e)

{

case '\120': ok10=(ok10+1)%(dem+1);break; //Neu an phim MUI TEN XUONG

case '\110': ok10=(ok10+dem)%(dem+1);break; //Neu an phim MUI TEN LEN

case '\015': ok10=dem+1;break; //Neu an phim ENTER

}

if(ok10!=dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" %s ",filename[ok10+1]);

}

if(ok10==dem&&ok10!=-1&&ok10!=dem+1)

{

textbackground(11);

textcolor(RED);

gotoxy(2,2+2*ok10);

cprintf(" Quay Lai ");

}

if (ok10==dem+1)

{

textmode(C80);

textmode(64);

clrscr();

textcolor(10);

clrscr();

if(fl10!=dem) thu=0;

else thu=1;

switch (thu)

{

case 0:mo=fopen(filename[oktam+1],"r");

if(mo==NULL) printf("EROOR Moi thu lai");

timkiem2(mo);

break;

case 1: ok10=dem+1;fl10=dem+1;break;

};

if (fl10!=dem+1) goto flag10;

if(fl10==dem+1) break;

}

fl10=ok10;

}

}

fclose(mo);

}//------------ket thuc ham Mo6-----------------

//ham tim kiem theo dieu kien TB>=5,ten,diem taon,diem ly,diem hao----------

void timkiem(FILE *fp,char dieukien[30],char tentam[20])

{

struct thongtin

{

char tenf[30];

char ngay[30];

char toan[30],ly[30],hoa[30],tb[30];

char rong[30];

}luutru[30];

int i,n,z=0;

clrscr();

//doc het

i=0;

fflush(stdin);

rewind(fp);

fgets(luutru[i].rong,2,fp);

while(!feof(fp))

{ flushall();

fgets(luutru[i].tenf,30,fp);

fgets(luutru[i].ngay,30,fp);

fgets(luutru[i].toan,30,fp);

fgets(luutru[i].ly,30,fp);

fgets(luutru[i].hoa,30,fp);

fgets(luutru[i].tb,30,fp);

fgets(luutru[i].rong,2,fp);

printf("%s",dieukien);

printf("%s",tentam);

i++;

}

n=i;

clrscr();

fclose(fp);

flushall();

for(i=0;i<n;i++)

{

flushall();

if(((strstr(luutru[i].tenf,dieukien)!=NULL)&&(strstr(luutru[i].tenf,tentam)!=NULL))||((strstr(luutru[i].toan,dieukien)!=NULL)&&(strstr(luutru[i].toan,tentam)!=NULL))||((strstr(luutru[i].ly,dieukien)!=NULL)&&(strstr(luutru[i].ly,tentam)!=NULL))||((strstr(luutru[i].hoa,dieukien)!=NULL)&&(strstr(luutru[i].hoa,tentam)!=NULL)))

{

flushall();z++;

printf("%s",luutru[i].tenf);

printf("%s",luutru[i].ngay);

printf("%s",luutru[i].toan);

printf("%s",luutru[i].ly);

printf("%s",luutru[i].hoa);

printf("%s",luutru[i].tb);

}

fflush(stdin);

};

if(z==0) printf("Khong co Ai thoa man yeu cau");

getch();

}

//-------------het ham---------------

//--------------ham tim kiem trung binh thap nhat--------

void timkiem1(FILE *fp)

{

struct thongtin

{

char tenf[30];

char ngay[30];

char toan[30],ly[30],hoa[30],tb[30];

char rong[30];

}luutru[30];

char min[30];

int i,n,h;

clrscr();

//doc het

i=0;

fflush(stdin);

rewind(fp);

fgets(luutru[i].rong,2,fp);

while(!feof(fp))

{ flushall();

fgets(luutru[i].tenf,31,fp);

fgets(luutru[i].ngay,31,fp);

fgets(luutru[i].toan,31,fp);

fgets(luutru[i].ly,31,fp);

fgets(luutru[i].hoa,31,fp);

fgets(luutru[i].tb,31,fp);

fgets(luutru[i].rong,2,fp);

i++;

}

n=i;

clrscr();

fclose(fp);

strcpy(min,luutru[0].tb);

h=0;

for(i=1;i<n;i++)

{

if(strcmpi(luutru[i].tb,min)<0)

h=i;

}

printf("nguoi co diem TB thap nhat la:

");

printf("%s",luutru[h].tenf);

printf("%s",luutru[h].ngay);

printf("%s",luutru[h].toan);

printf("%s",luutru[h].ly);

printf("%s",luutru[h].hoa);

printf("%s",luutru[h].tb);

getch();

}

//-------------het ham---------------

//ham tim kiem theo dieu kien TB>=5----------

void timkiem4(FILE *fp,char dieukien[30])

{

struct thongtin

{

char tenf[30];

char ngay[30];

char toan[30],ly[30],hoa[30],tb[30];

char rong[30];

}luutru[30];

int i,n,z=0;

clrscr();

//doc het

i=0;

fflush(stdin);

rewind(fp);

fgets(luutru[i].rong,2,fp);

while(!feof(fp))

{ flushall();

fgets(luutru[i].tenf,30,fp);

fgets(luutru[i].ngay,30,fp);

fgets(luutru[i].toan,30,fp);

fgets(luutru[i].ly,30,fp);

fgets(luutru[i].hoa,30,fp);

fgets(luutru[i].tb,30,fp);

fgets(luutru[i].rong,2,fp);

i++;

}

n=i;

clrscr();

fclose(fp);

flushall();

for(i=0;i<n;i++)

{

flushall();

if((strcmpi(luutru[i].tb,dieukien)>0))

{

flushall();z++;

printf("%s",luutru[i].tenf);

printf("%s",luutru[i].ngay);

printf("%s",luutru[i].toan);

printf("%s",luutru[i].ly);

printf("%s",luutru[i].hoa);

printf("%s",luutru[i].tb);

}

fflush(stdin);

};

if(z==0) printf("Khong co Ai thoa man yeu cau");

getch();

}

//-------------het ham---------------

//--------------ham tim kiem trung binh cao nhat--------

void timkiem2(FILE *fp)

{

struct thongtin

{

char tenf[30];

char ngay[30];

char toan[30],ly[30],hoa[30],tb[30];

char rong[30];

}luutru[30];

char max[30];

int i,n,h;

clrscr();

//doc het

i=0;

fflush(stdin);

rewind(fp);

fgets(luutru[i].rong,2,fp);

while(!feof(fp))

{ flushall();

fgets(luutru[i].tenf,31,fp);

fgets(luutru[i].ngay,31,fp);

fgets(luutru[i].toan,31,fp);

fgets(luutru[i].ly,31,fp);

fgets(luutru[i].hoa,31,fp);

fgets(luutru[i].tb,31,fp);

fgets(luutru[i].rong,2,fp);

i++;

}

n=i;

clrscr();

fclose(fp);

strcpy(max,luutru[0].tb);

h=0;

for(i=1;i<n;i++)

{

if(strcmpi(luutru[i].tb,max)>0)

h=i;

}

printf("nguoi co diem TB cao nhat la:

");

printf("%s",luutru[h].tenf);

printf("%s",luutru[h].ngay);

printf("%s",luutru[h].toan);

printf("%s",luutru[h].ly);

printf("%s",luutru[h].hoa);

printf("%s",luutru[h].tb);

getch();

}

//-------------het ham---------------

//--------------Chuong trinh Chinh---------------------

void main()

{ FILE *xemlaitep;

xemlaitep=fopen("demtep.txt","r");

if(xemlaitep==NULL);

else

fscanf(xemlaitep,"%d",&dem);

printf("%d",dem);

fclose(xemlaitep);

MENU();

}//-----------het chuong trinh----------

bài tập quản lý khách sạn

________________________________________

Code:

#include<conio.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define MAX 100

struct TIME

{

char phut;

char gio;

char ngay;

};

typedef struct ks

{

char phong[];

char hoten[30];

struct TIME d;

} hotel[MAX];

int n=1;

void menu()

{

printf("

+++++++ MENU +++++++++ ");

printf("

++ +++++ ");

printf("

++ 1. THUE PHONG +++++ ");

printf("

++ 2. TRA PHONG +++++ ");

printf("

++ 3. THONG TIN +++++ ");

printf("

++ 4. THOAT +++++ ");

printf("

+++++++++++++++++++++++ ");

printf("

Lua chon ? ");

}

void main()

{

char ch;

menu();

do{

ch=getch();

}

while(ch <'1' || ch>'4' );

switch(ch)

{

case '1': break;

case '2': break;

case '3': break;

case '4': exit(1);

default: printf(" chua chon dung");

}

getch();

}

bài tập C về tam giác Tam Giác

#include <stdio.h>

#include <math.h>

// Khai bao kieu DIEM & TAMGIAC

typedef struct

{

int x; // tung do

int y; // hoanh do

} DIEM;

typedef struct

{

DIEM dA;

DIEM dB;

DIEM dC;

} TAMGIAC;

// Nguyen mau ham

void NhapDiem(DIEM &d);

void XuatDiem(DIEM d, char *thongbao);

float TinhKhoangCach(DIEM d1, DIEM d2);

int KiemTraTamGiac(TAMGIAC tg);

void NhapTamGiac(TAMGIAC &tg);

void XuatTamGiac(TAMGIAC tg, char *thongbao);

float TinhChuVi(TAMGIAC tg);

float TinhDienTich(TAMGIAC tg);

void main()

{

TAMGIAC tg;

NhapTamGiac(tg);

XuatTamGiac(tg, "Toa do ba diem cua Tam giac:

");

printf("Chu vi Tam giac = %.2f

", TinhChuVi(tg));

printf("Dien tich Tam giac = %.2f

", TinhDienTich(tg));

}

// Dinh nghia ham

void NhapDiem(DIEM &d)

{

printf("Nhap tung do x: ");

scanf("%d", &d.x);

printf("Nhap hoanh do y: ");

scanf("%d", &d.y);

}

void XuatDiem(DIEM d, char *thongbao)

{

printf("%s", thongbao);

printf("(%d, %d)

", d.x, d.y);

}

float TinhKhoangCach(DIEM d1, DIEM d2)

{

float kq;

int dx = d1.x - d2.x;

int dy = d1.y - d2.y;

kq = sqrt(float(dx*dx + dy*dy));

return kq;

}

int KiemTraTamGiac(TAMGIAC tg)

{

float AB, AC, BC;

AB = TinhKhoangCach(tg.dA, tg.dB);

AC = TinhKhoangCach(tg.dA, tg.dC);

BC = TinhKhoangCach(tg.dB, tg.dC);

if (AC + BC > AB && AB + BC > AC && AB + AC > BC)

return 1;

else

return 0;

}

void NhapTamGiac(TAMGIAC &tg)

{

int hople;

do

{

printf("Nhap toa do Diem A:

");

NhapDiem(tg.dA);

printf("Nhap toa do Diem B:

");

NhapDiem(tg.dB);

printf("Nhap toa do Diem C:

");

NhapDiem(tg.dC);

hople = KiemTraTamGiac(tg);

if (!hople)

printf("Nhap lai! Tam giac khong hop le.

");

}

while (!hople);

}

void XuatTamGiac(TAMGIAC tg, char *thongbao)

{

printf("%s", thongbao);

XuatDiem(tg.dA, "- Toa do Diem A: ");

XuatDiem(tg.dB, "- Toa do Diem B: ");

XuatDiem(tg.dC, "- Toa do Diem C: ");

}

float TinhChuVi(TAMGIAC tg)

{

float P, AB, AC, BC;

AB = TinhKhoangCach(tg.dA, tg.dB);

AC = TinhKhoangCach(tg.dA, tg.dC);

BC = TinhKhoangCach(tg.dB, tg.dC);

P = AB + AC + BC;

return P;

}

float TinhDienTich(TAMGIAC tg)

{

float S, p, AB, AC, BC;

AB = TinhKhoangCach(tg.dA, tg.dB);

AC = TinhKhoangCach(tg.dA, tg.dC);

BC = TinhKhoangCach(tg.dB, tg.dC);

p = (AB + AC + BC) / 2;

S = sqrt(p * (p - AB) * (p - AC) * (p - BC));

return S;

}

viết chương trình QUẢN LÝ SINH VIÊN

#include <stdio.h>

#include <conio.h>

#include <string.h>

#define max 100

typedef struct { char ho[10]; char tendem[20];char ten [10]; } hoten;

typedef struct {float toan; float ly; float hoa;} diem;

typedef struct {hoten HVT; char quequan[30]; char truong[50];

unsigned char tuoi; int SBD; diem diemthi;}

sinhvien;

void nhaphoten(hoten *HVT)

{ char st[20];

printf("

Ho : ");

fflush(stdin);

strcpy(HVT->ho,st);

printf("

Ten dem : ");

fflush(stdin);

strcpy(HVT->tendem,st);

printf("

Ten : ");

fflush(stdin);

strcpy(HVT->ten,st);

}

void nhapdiem(diem *d)

{ float temp;

printf("

Diem toan: ");

scanf("%f",&temp);

d->toan=temp;

printf("

Diem ly : ");

scanf("%f", &temp);

d->ly=temp;

printf("

Diem hoa : ");

scanf("%f", &temp);

d->hoa=temp;

}

void nhap(sinhvien ds[max],int *n)

{ char st1[30];

unsigned char t;

int sbd,i;

printf("nhap vao so thi sinh:");

scanf("%d",n);

for(i=0;i<*n;i++)

{ printf("nhap thong tin thi sinh %d:

",i+1);

printf(" ho va ten:

");

nhaphoten(&ds[i].HVT);

printf(" diem thi:

");

nhapdiem(&ds[i].diemthi);

printf("truong:

");

fflush(stdin);

gets(st1);

strcpy(ds[i].truong,st1);

printf(" que quan:

");

fflush(stdin);

gets(st1);

strcpy(ds[i].quequan,st1);

printf("tuoi:

");

scanf("%d",&t);

ds[i].tuoi=t;

printf("SBD:

");

scanf("%d",&sbd);

ds[i].SBD=sbd;

}

}

void hienthi(sinhvien ds[max],int n)

{ int i;

printf("

+---+------------------+--------+------+-----+-----+-----+-----+-----+");

printf("

|STT| HO VA TEN |que quan|truong|tuoi | SBD | toan| ly | hoa |");

printf("

+---+------------------+--------+------+-----+-----+-----+-----+-----+");

for (i=0; i<n; i++)

printf("

| %3d |%5s %10s %5s| %8s| %10s | %4d | %4d |% 2.2f|%2.2f|%2.2f",i+1,

ds[i].HVT.ho,ds[i].HVT.tendem,ds[i].HVT.ten,ds[i].quequan, ds[i].truong, ds[i].tuoi, ds[i].SBD,ds[i].diemthi.toan,ds[i].diemthi.ly,ds[i].diemthi.hoa);

printf("

+---+------------------+--------+------+-----+-----+-----+-----+-----+");

}

void main()

{ int n;

sinhvien dsts[max];

nhap(dsts,&n);

printf("Danh Sach Tuyen Sinh nam 2009:

");

hienthi(dsts,n);

getch();

}

Bạn đang đọc truyện trên: Truyen2U.Pro

#hoangnam