Bài tập Turbo C có Đáp án

doc 98 trang hoanguyen 3900
Bạn đang xem 20 trang mẫu của tài liệu "Bài tập Turbo C có Đáp án", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • docbai_tap_turbo_c_co_dap_an.doc

Nội dung text: Bài tập Turbo C có Đáp án

  1. Bài tập: Chương 1: 01: #include /* Hay so sanh tap tin .exe voi BT01_03 */ main() { printf(" Chao ban !"); /* Co trong tap stdio.h */ printf("Moi ban lam quen voi Turbo C"); getch(); /* Dung man hinh de xem ket qua */ } 02 #include #include main() { clrscr(); printf(" Chao ban !"); printf("Moi ban lam quen voi Turbo C"); getch(); } 03 #include /* Hay so sanh tap tin .exe voi BT01_01 */ main() { clrscr(); /* Cau lenh xoa man hinh */ cprintf(" Chao ban !\n"); /* Co trong tap conio.h */ cprintf("Moi ban lam quen voi Turbo C"); getch(); } 04 #include main() { clrscr(); cprintf(" Chao ban !\n\r"); /* Them dinh dang \r de ve dau dong */ cprintf("Moi ban lam quen voi Turbo C"); getch(); } 05
  2. #include main() { char ten[150]; printf("Cho biet ten cua ban \n"); scanf("%s",ten); printf("Chao ban :%s\n",ten); getch(); } 06 #include main() { clrscr(); printf(" HOI THOAI VE TURBO C \n"); printf("-SON : Nghe noi hoc Turbo C kho lam phai khong ?\n"); printf("-HA : Cung nghe noi vay, nhung khong biet co dung khong ? \n"); printf("-XA : Thi cung tuong tu nhu Pascal vay thoi \n"); printf("-TAC : Ban da hoc roi phai khong, noi cho nghe di nao \n"); printf("-XA : Cung thuoc loai lap trinh cau truc nhung chay nhanh hon nhieu \n"); getch(); } 07 #include main() { clrscr(); cprintf(" AO THU \n\r"); cprintf("\n"); cprintf("Ao thu lanh leo nuoc trong veo\n\r"); cprintf("Mot chiec thuyen con be teo teo\n\r"); cprintf("Song biec theo lan hoi gon ty\n\r"); cprintf("La vang truoc gio se dua veo\n\r"); cprintf("\n\r"); cprintf(" NGUYEN KHUYEN"); getch(); } 08 #include main() {
  3. int a,b,tong,hieu,tich; /*Khai bao 4 bien so nguyen */ float thuong; /* Khai bao bien so thuc */ clrscr(); /* Lenh xoa man hinh */ printf("Nhap so thu nhat : "); scanf("%d",&a); /* Lenh nhap so lieu tu ban phim va gan cho bien */ printf("Nhap so thu hai : "); scanf("%d",&b); tong = a+b; hieu = a-b; tich= a*b; thuong= (float)a/b; /* Chuyen doi kieu so nguyen sang so thuc */ printf("\n"); printf("Tong cua 2 so a=%d va b=%d la=%d\n",a,b,tong); printf("Hieu cua 2 so a=%d va b=%d la=%d\n",a,b,hieu); printf("Tich cua 2 so a=%d va b=%d la=%d\n",a,b,tich); printf("Thuong cua 2 so a=%d va b=%d la=%f\n",a,b,thuong); getch(); } 09 /* Chuong trinh Tinh chu vi va dien tich hinh tron */ #include "stdio.h" main() { float r,c,s; printf("- Cho biet ban kinh r= "); scanf("%f",&r); c=6.28*r; s=3.14*r*r; /*In ket qua tren 3 dong*/ clrscr(); printf(" KET QUA TINH CHU VI DIEN TICH HINH TRON \n"); printf(" -Ban kinh hinh tron r = %8.2f met \n",r); printf(" -Chu vi hinh tron c = %8.2f met \n",c); printf(" -Dien tich hinh tron s = %8.2f met vuong \n",s); getch(); } 10 /*Chuong trinh tinh x luy thua y*/ #include"stdio.h" #include "math.h" main() {
  4. double pow(); /*khai bao ham pow kieu double*/ double x,y,z; /* khai bao 3 bien kieu double*/ clrscr(); printf("- Cho biet gia tri cua X= "); scanf("%lf",&x); printf("- Cho biet gia tri cua Y= "); scanf("%lf",&y); z=pow(x,y); /* Tinh x luy thua y va gan cho z */ /* In ket qua */ clrscr(); printf("KET QUA CUA CHUONG TRINH TINH X LUY THUA Y \n"); printf("- X= %8.2f \n",x); printf("- Mu Y= %8.2f \n",y); printf("* X luy thua y = %8.2f",z); getch(); } Chương 2 05: main() { clrscr(); printf("Truong Dai Hoc Tai Chanh Ke Toan"); printf("Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n "); printf("Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n "); printf("\n Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n "); printf("\n\t Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n "); printf("\n\t\t Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n\t\t\r Truong Dai Hoc Tai Chanh Ke Toan \n "); printf("\n "); printf("\n\t\t\r Truong \a Dai \a Hoc \a Tai \a" "Chanh \a Ke \a Toan \a "); printf("\n\t\t\r Truong \a Dai \a Hoc \a Tai \a ", "Chanh \a Ke \a Toan \a "); getch(); }
  5. 06 /* Chuong trinh su dung cac ky tu dieu khien */ #include main() { clrscr(); printf("\n Day la dau nhay don \'Turbo C 2.0 \'"); printf("\n"); printf("\n Va day la dau nhay kep \"Turbo C\" "); printf("\n"); printf("\n Duong dan vao file stdio.h la \"C:\\TC\\INCLUDE\\stdio.h\""); printf("\n\n File Edit Run Compile Project Debug Break/watch"); printf("\n EDIT \n\b COMPILE \n\b DEBUG \n\b WATCH "); printf("\n EDIT \a COMPILE \a DEBUG \a WATCH "); getch(); } 07 #include"stdio.h" main() { clrscr(); cprintf(" Day la nua tren dau tich phan : ma Ascii ," "he 16 la F4 \xF4 \n"); cprintf("\n\r\ Day la nua duoi dau tich phan : ma Ascii," "he 16 la F5 \xF5 \n"); cprintf("\n\r Day la ca dau tich phan "); cprintf("\n\r"); cprintf(" \xF4"); /*tao nguyen dau tich phan */ cprintf("\n\b\xF5"); getch(); } 08 #include"stdio.h" char c=97; main() { clrscr(); printf("\nc=%c\t c=%d",c,c); getch(); } 09
  6. #include main() { char a='2'; unsigned char b='7'; int c=-23; unsigned int d=124; float re=675.89; float rm = 0.000887; float rt = 0.0000887; clrscr(); printf("\na= %c, \tb=%c",a,b); printf("\nc=+%04d\td=%03d\tc=%4d\td=%3d",c,d,c,d); printf("\nd=%o\td=%x\td=%X",d,d,d); printf("\nre= %6.3f \trm= %6.3g ",re,rm); printf("\nrt= %6.3g \trm= %6.3G ",rt,rm); printf("\ntrt= %6.3G",rt); getch(); } 10 #include main() { float a,b,c,d,e,f; clrscr(); printf("\n-Nhap so thu nhat = "); scanf("%f",&a); printf("\n-Nhap so thu hai = "); scanf("%f",&b); printf("\n-Nhap so thu ba = "); scanf("%f",&c); printf("\n-Nhap so thu tu = "); scanf("%f",&d); e=a+b+c+d; printf("\n\a * Tong cua 4 so vua nhap vao = %f",e); f=(a+b+c+d)/4; printf("\n\ * Trung \a binh \a cong \a cua \a 4 \a so \a la = %f",f); getch(); } 11 #include main()
  7. { char ten[150]; /*long ng_cong,b_lg,t_ung;*/ float luong,c_linh,h_so,ng_cong,b_lg,t_ung; clrscr(); printf("\n Cho biet Ten = "); scanf("%s",&ten); printf("\n Cho biet bac luong = "); scanf("%f",&b_lg); printf("\n Cho biet so ngay lam viec = "); scanf("%f",&ng_cong); printf("\n Cho biet he so phu cap = "); scanf("%f",&h_so); printf("\n Cho biet so tien da tam ung = "); scanf("%f",&t_ung); luong=(b_lg/30)*ng_cong*h_so; c_linh=luong-t_ung; printf("\n"); printf("\n ___"); printf("\n"); printf("\n Ong/Ba :%s ",ten); printf("\n So tien luong duoc huong = %.2f",luong); printf("\n So tien da tam ung = %.2f",t_ung); printf("\n So tien con duoc lanh = %.2f",c_linh); getch(); } 12 main() { int thap,cao,khoang; float fahr,celsius; thap=0; cao=320; khoang=20; fahr=thap; clrscr(); printf("BANG DOI DO FRENHEIT RA CELSIUS\n"); printf("\n"); printf("===\n"); printf("| Frenheit | Celsius |\n"); printf(" \n");
  8. while(fahr <= cao) /* Lenh vong lap,se hoc o chuong 4 */ { celsius=(5.0/9)*(fahr-32.0); printf("| %4.0f | %6.1f |\n",fahr,celsius); fahr=fahr+khoang; } printf("===\n"); getch(); } Chương 3: 01: main() { int i; clrscr(); printf("\nNhap so he 10 la = "); scanf("%d",&i); printf("\nChuyen sang he 8 la = %o",i); printf("\nChuyen sang he 16 la = %x",i); getch(); } 02 /* Vi du ve cac phep toan so hoc */ main() { int i=10,j=4,x1,k; float x; k=i+j; clrscr(); printf("\nLuc dau ban co 2 so nguyen i=10, j=4\n\n"); printf("Tong cua 2 so nguyen = %d\n\n",k); x=i; printf("Gan tri cua i ( kieu int ) cho x ( kieu float ) thi X= %f\n\n",x); x1=i/j; printf("Thuong so cua ( int ) i/j = %d\n\n",x1); x=(float)i/j; printf("Thuong so cua (loat) i/j = %f\n\n",x); k=i%j; printf("Du so cua phep chia nguyen = %d\n\n",k); x=1.5;i=5;
  9. printf("Gan x=1.5 va i=5 Tong cua 2 so =%f\n",x+i); getch(); } 03 /* Phep toan quan he */ main() { int i,j; clrscr(); printf("\nNhap so thu nhat = "); scanf("%d",&i); printf("\nNhap so thu hai = "); scanf("%d",&j); printf("\nSo %d > %d : %d ",i,j,i>j); printf("\nSo %d = %d : %d ",i,j,i>=j); printf("\nSo %d main() {
  10. int i,j; clrscr(); printf("\nNhap so thu nhat (i) = "); scanf("%d",&i); printf("\nNhap so thu hai (j) = "); scanf("%d",&j); printf("\nPhep ~%d : %d ",i,~i); printf("\nSo %d & %d : %d (He 10)",i,j,i&j); printf("\nSo %d & %d : %o (He 8)",i,j,i&j); printf("\nSo %d & %d : %X (He 16)",i,j,i&j); printf("\nSo %d | %d : %d (He 10)",i,j,i|j); printf("\nSo %d | %d : %o (He 8)",i,j,i|j); printf("\nSo %d | %d : %X (He 16)",i,j,i|j); printf("\nSo %d ^ %d : %d (He 10)",i,j,i^j); printf("\nSo %d ^ %d : %o (He 8)",i,j,i^j); printf("\nSo %d ^ %d : %X (He 16)",i,j,i^j); getch(); } 06 /* Phep toan dich trai */ main() { int i,j,n; clrscr(); printf("\nNhap mot so nguyen = "); scanf("%d",&i); printf("\nCan dich trai may bit= "); scanf("%d",&n); j=i<<n; printf("\nSo %d dich trai %d bit co tri (He 10) la = %d",i,n,j); printf("\nSo %d dich trai %d bit co tri (He 8 ) la = %o",i,n,j); printf("\nSo %d dich trai %d bit co tri (He 16) la = %X",i,n,j); getch(); } 07 /* Phep toan dich phai kieu unsigned */ main() { unsigned i,j,n; clrscr(); printf("\nNhap mot so nguyen = ");
  11. scanf("%d",&i); printf("\nCan dich phai may bit= "); scanf("%d",&n); j=i>>n; printf("\nSo %d dich trai %d bit co tri (He 10) la = %d",i,n,j); printf("\nSo %d dich trai %d bit co tri (He 8 ) la = %o",i,n,j); printf("\nSo %d dich trai %d bit co tri (He 16) la = %X",i,n,j); getch(); } 08 /* Phep toan dich phai kieu signed */ main() { int i,j,n; clrscr(); printf("\nNhap mot so nguyen = "); scanf("%d",&i); printf("\nCan dich phai may bit= "); scanf("%d",&n); j=i>>n; printf("\nSo %d dich trai %d bit co tri (He 10) la = %d",i,n,j); printf("\nSo %d dich trai %d bit co tri (He 8 ) la = %o",i,n,j); printf("\nSo %d dich trai %d bit co tri (He 16) la = %X",i,n,j); getch(); } 09 /*Hay du doan ket qua cua chuong trinh sau */ main() { int a=4,b=6,n; clrscr(); n=a+b; printf("a=%d\tb=%d\tn=%d\n",a,b,n); n=++a +b; printf("a=%d\tb=%d\tn=%d\n",a,b,n); n=a++ +b; printf("a=%d\tb=%d\tn=%d\n",a,b,n); n= a +b; printf("a=%d\tb=%d\tn=%d\n",a,b,n); n=a +b;
  12. printf("a=%d\tb=%d\tn=%d\n",a,b,n); n=a+b; printf("a=%d\tb=%d\tn=%d\n",a,b,n); getch(); } 10 /* Phep toan dieu kien */ main() { int a,b; clrscr(); printf("\nNhap so thu nhat= "); scanf("%d",&a); printf("\nNhap so thu hai = "); scanf("%d",&b); printf("\nSo lon hon trong 2 so vua nhap la so %d ",(a>b) ? a:b); getch(); } 11 /* Du doan ket qua truoc khi chay chuong trinh */ main() { clrscr(); printf("\n1.5*(11/3)=%6.2f\n1.5*11/3=%6.2f",1.5*(11/3),1.5*11/3); printf("\n(11/3)*1.5=%6.2f\n11/3*1.5=%6.2f",(11/3)*1.5,11/3*1.5); printf("\n11/3+1.5 =%6.2f",11/3+1.5); printf("\n\nGia tri cua quan he 3 > 7 la :%3d",3>7); printf("\n\nGia tri cua quan he 7 3); printf("\nGia tri cua phep toan 3&&7 la : %3d",3&&7); { int x=10,y=11; /* khong than trong khi dung phep toan tang giam */ printf("\n\nKhi x=10 va y=11 thi cau lenh"); printf("\ printf(\"\\n\\n%6 d\\n%6 d\\n%6 d\","); printf("\n x * ++y,x - y,x++ + ++y);"); printf("\n\n se in ra :(gia tri sai)"); printf("\n\n%6d\n%6d\n%6d",x * ++y,x - y,x++ + ++y); } getch(); }
  13. 12 /* Hay du du doan ket qua truoc khi chay chuong trinh */ main() { int x=10,y=11; clrscr(); printf("\nKhi x=10 va y=11 thi gia tri cua"); printf("\n\n x * ++y\n x - y\n x++ + ++y\n"); printf("\n\n se la :\n"); printf("\n%10d",x * ++y); printf("\n%10d",x - y); printf("\n%10d",x++ + ++y); getch(); } Chương 5 01: /*Tim so lon nhat trong 2 so thuc */ /*Cau truc if thieu */ main() { float a,b,max; int k; tt:clrscr(); printf("\nNhap so thu nhat (a) = "); scanf("%f",&a); printf("\nNhap so thu hai (b) = "); scanf("%f",&b); max=a; if(b>a) max=b; printf("\na= %8.2f",a); printf("\nb= %8.2f",b); printf("\n\nSo lon nhat trong hai so la =%8.2f",max); printf("\n\n Tiep tuc nua khong ? (0/1)"); printf("\n(Go so 1 de tiep tuc, so 0 de ket thuc) "); scanf("%d",&k); if(k==1) goto tt;
  14. } 02 /* Tim so lon nhat cua 2 so thuc */ /* Cau lenh if du */ main() { float a,b,max; int k; tt:clrscr(); printf("\nNhap so thu nhat (a) = "); scanf("%f",&a); printf("\nNhap so thu hai (b) = "); scanf("%f",&b); if(a>b) max=a; else max=b; printf("\n\So lon nhat trong hai so la =%8.2f",max); printf("\n\n Tiep tuc (go so 1)/dung (go so 0)"); scanf("%d",&k); if(k==1) goto tt; } 03 /* Tim so lon nhat trong 4 so nguyen */ /* Cau truc if du */ main() { int a,b,c,d,max1,max2,max,t; tt:clrscr(); printf("\nCHUONG TRINH TIM SO NGUYEN LON NHAT TRONG 4 SO"); printf("\nNhap so thu nhat : "); scanf("%d",&a); printf("\nNhap so thu hai : "); scanf("%d",&b); printf("\nNhap so thu ba : "); scanf("%d",&c); printf("\nNhap so thu tu : "); scanf("%d",&d); if (a > b) max1=a;
  15. else max1=b; if (c > d) max2=c; else max2=d; if (max1 > max2) { max=max1; clrscr(); printf("\n KET QUA"); printf("\nTrong 4 so vua nhap"); printf("\nSo thu nhat = %4d ",a); printf("\nSo thu hai = %4d ",b); printf("\nSo thu ba = %4d ",c); printf("\nSo thu tu = %4d ",d); printf("\nSo lon nhat trong 4 so la = %4d ",max); } else { max=max2; clrscr(); printf("\n KET QUA"); printf("\nTrong 4 so vua nhap"); printf("\nSo thu nhat = %4d ",a); printf("\nSo thu hai = %4d ",b); printf("\nSo thu ba = %4d ",c); printf("\nSo thu tu = %4d ",d); printf("\nSo lon nhat trong 4 so la = %4d ",max); } printf("\n\n Tiep tuc (bam so 1) / Cham dut (bam so 0) "); scanf("%d",&t); if (t==1) goto tt; } 04 /* Chuyen ky tu tu aA-fF sang ky so he 16 */ /* Cau truc else if */ main() { char c,k;
  16. clrscr(); printf("\nHay nhap mot ky tu tu aA den fF : "); scanf("\n%c",&c); clrscr(); if (c >='0' && c ='A' && c = 'a' && c<= 'f') k=c-'a'+10; else k=0; printf("\nNeu ban nhap vao ky tu la :%c\n",c); printf("\nLa ky so thu : %d cua he 16",k); getch(); } 05 /* Cau truc if long nhau */ main() { int gio,gio1,phut,phut1,giay,giay1,them,t; tt:clrscr(); gio=0; phut=0; giay=0; them=0; printf("\nCHUONG TRINH TINH THOI GIAN"); printf("\n-Cho biet gio : "); scanf("%2d",&gio); gio1=gio; printf("-Cho biet phut : "); scanf("%2d",&phut); phut1=phut; printf("-Cho biet giay : "); scanf("%2d",&giay); giay1=giay; printf("-Cho biet giay muon them vao : "); scanf("%2d",&them); if ((giay+them) < 60) giay=giay+them; else
  17. { giay=giay+them-60; phut=phut+1; if (phut >=60) { phut=phut-60; gio=gio+1; } } printf("\n*Luc dau la %2d : %2d : %2d ",gio1,phut1,giay1); printf("\n*Neu ban cong them : %2d giay ",them); printf("\n*Gio moi la= %2d : %2d : %2d ",gio,phut,giay); printf("\n\n Tiep tuc (bam so 1) / Cham dut (bam so 0) "); scanf("%d",&t); if (t==1) goto tt; } 06 /* Chuong trinh giai phuong trinh bac 2 */ main() { float a,b,c,x1,x2,denta; int k; tt:clrscr(); printf("\Giai phuong trinh bac hai"); printf("\nNhap he so a = "); scanf("%f",&a); printf("\Nhap he so b = "); scanf("%f",&b); printf("\Nhap he so c = "); scanf("%f",&c); denta=b*b-4*a*c; if (denta<0) printf("\nPHUONG TRINH VO NGHIEM"); else if(denta==0) printf("\nPHUONG TRINH CO NGHIEM KEP X1=X2 =%8.2f ",-b/(2*a)); else {
  18. denta=sqrt((double)denta); x1=(-b-denta)/(2*a); x2=(-b+denta)/(2*a); printf("\nPhuong trinh co hai nghiem:"); printf("\n\nNghiem thu nhat X1 =%8.2f ",x1); printf("\nNghiem thu hai X2 =%8.2f ",x2); } printf("\n\nTiep tuc (bam 1).Cham dut (bam 0) "); scanf("%d",&k); if (k==1) goto tt; } 07 main() { int i,tt; kk:clrscr(); printf("\nHUONG DAN MUA VE MAY BAY DI CAC TUYEN DUONG"); printf("\nCac tuyen bay trong nuoc"); printf("\n 1-Ha Noi"); printf("\n 2-Da Nang"); printf("\n 3-Buon Ma Thuot"); printf("\n 4-Dien Bien Phu"); printf("\n 5-Phu Quoc"); printf("\n 6-Con Dao"); printf("\n\nCac tuyen bay Quoc te"); printf("\n 7- New York"); printf("\n 8- London"); printf("\n 9- Paris"); printf("\n 10-Moscow"); printf("\n 11-Bac Kinh"); printf("\n 12-Taiwan"); printf("\n 13-Binh Nhuong"); printf("\n 14-Bankoc"); printf("\n 15-Tokyo"); printf("\nNhap vao mot so tu 1 den 15 : "); scanf("%2d",&i); switch(i) { case 1: goto t1;
  19. case 2: goto t2; case 3: goto t3; case 4: goto t4; case 5: goto t5; case 6: goto t6; case 7: goto t7; case 8: goto t8; case 9: goto t9; case 10: goto t10; case 11: goto t11; case 12: goto t12; case 13: goto t13; case 14: goto t14; case 15: goto t15; t1:printf("\n Quy khach di tuyen Ha Noi"); printf("\n XIN MOI DEN PHONG SO 1, Lau 1"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t2:printf("\n Quy khach di tuyen Da Nang"); printf("\n XIN MOI DEN PHONG SO 2, Lau 1"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t3:printf("\n Quy khach di tuyen Buon Ma Thuot"); printf("\n XIN MOI DEN PHONG SO 3, Lau 1"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t4:printf("\n Quy khach di tuyen Dien Bien Phu"); printf("\n XIN MOI DEN PHONG SO 4, Lau 1"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t5:printf("\n Quy khach di tuyen Phu Quoc");
  20. printf("\n XIN MOI DEN PHONG SO 5, Lau 1"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t6:printf("\n Quy khach di tuyen Con Dao"); printf("\n XIN MOI DEN PHONG SO 6, Lau 1"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t7:printf("\n Quy khach di tuyen New York"); printf("\n XIN MOI DEN PHONG SO 1, Lau 2"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t8:printf("\n Quy khach di tuyen London"); printf("\n XIN MOI DEN PHONG SO 2, Lau 2"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t9:printf("\n Quy khach di tuyen Paris"); printf("\n XIN MOI DEN PHONG SO 3, Lau 2"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t10:printf("\n Quy khach di tuyen Moscow"); printf("\n XIN MOI DEN PHONG SO 4, Lau 2"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t11:printf("\n Quy khach di Bac Kinh"); printf("\n XIN MOI DEN PHONG SO 1, Lau 3");
  21. printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t12:printf("\n Quy khach di Taiwan"); printf("\n XIN MOI DEN PHONG SO 2, Lau 3"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t13:printf("\n Quy khach di Binh Nhuong"); printf("\n XIN MOI DEN PHONG SO 3, Lau 3"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t14:printf("\n Quy khach di Bankoc"); printf("\n XIN MOI DEN PHONG SO 4, Lau 3"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; break; t15:printf("\n Quy khach di Tokyo"); printf("\n XIN MOI DEN PHONG SO 5, Lau 3"); printf("\nTiep tuc (Bam so 1)/Cham dut (Bam so 0)"); scanf("%d",&tt); if (tt==1) goto kk; } } 08 #include main() { int c; /* In ra cau hoi va 4 cau tra loi */
  22. clrscr(); tt:printf("\n\nAi la nguoi da de xuat ra ngon ngu Turbo C"); printf("\n\nA)-Brian Kernighan ?\nB)-Ken Thompson ?"); printf("\nC)-Dennis Ritchie ?\nD)-Niklau Wirth ?"); printf("\n\nHay go vao cau tra loi tu aA den dD "); /*Cho nhan mot ky tu va kiem tra de thong bao */ scanf("%d",&c); switch (c=getchar()) { case 'A': case 'a': case 'B': case 'b': case 'D': case 'd':printf(" "); printf("\n * Ban tra loi khong dung ! *\n"); printf("\ "); goto tt; case 'C': case 'c': printf(" "); printf("\n * Ban da tra loi dung ! *\n"); printf("\ "); break; case'\n':break; default:printf(" Chi tra loi tu A den D thoi !"); break; } getch(); } 09 main() { int i,tt; float a,b,c,r,dt; kk:clrscr(); printf("\nCHUONG TRINH TINH DIEN TICH HINH HOC SO CAP"); printf("\n 1-Hinh vuong"); printf("\n 2-Hinh chu nhat"); printf("\n 3-Hinh tam giac"); printf("\n 4-Hinh thang"); printf("\n 5-Hinh tron");
  23. printf("\nBam so (0) de thoat "); printf("\nNhap vao mot so tu 1 den 5 de tinh: "); scanf("%1d",&i); switch(i) { case 0: goto thoat; case 1: goto hv; case 2: goto cn; case 3: goto tg; case 4: goto ht; case 5: goto tr; hv:printf("\n CHUONG TRINH TINH DIEN TICH HINH VUONG"); printf("\nCho biet canh hinh vuong = "); scanf("%f",&a); dt=a*a; printf("\nDien tich hinh vuong la : %8.2f",dt); printf("\n\n Tiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&tt); if (tt==1) goto kk; break; cn:printf("\n CHUONG TRINH TINH DIEN TICH HINH CHU NHAT"); printf("\nCho biet chieu dai = "); scanf("%f",&a); printf("\nCho biet chieu rong = "); scanf("%f",&b); dt=a*b; printf("\nDien tich hinh chu nhat la : %8.2f",dt); printf("\n\n Tiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&tt); if (tt==1) goto kk; break; tg:printf("\n CHUONG TRINH TINH DIEN TICH HINH TAM GIAC"); printf("\nCho biet canh day = "); scanf("%f",&a); printf("\nCho biet chieu cao = "); scanf("%f",&c); dt=a*c/2; printf("\nDien tich hinh tam giac la : %8.2f",dt);
  24. printf("\n\n Tiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&tt); if (tt==1) goto kk; break; ht:printf("\n CHUONG TRINH TINH DIEN TICH HINH THANG"); printf("\nCho biet day dai = "); scanf("%f",&a); printf("\nCho biet day ngan = "); scanf("%f",&b); printf("\nCho biet chieu cao = "); scanf("%f",&c); dt=(a+b)*c/2; printf("\nDien tich hinh thang la : %8.2f",dt); printf("\n\n Tiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&tt); if (tt==1) goto kk; break; tr:printf("\n CHUONG TRINH TINH DIEN TICH HINH TRON"); printf("\nCho biet ban kinh = "); scanf("%f",&r); dt=r*r*3.1416; printf("\nDien tich hinh thang la : %8.2f",dt); printf("\n\n Tiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&tt); if (tt==1) goto kk; thoat:break; } } 10 main() { int nam,n; tt:clrscr(); printf("\nCHUONG TRINH TINH NAM NHUAN"); printf("\nCho biet nam can tinh (?) : ");
  25. scanf("%4d",&nam); switch (nam % 4) { case 0:printf("\nNam %4d ",nam); printf("La nam nhuan"); printf("\n\nTiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&n); if (n==1) goto tt; break; case 1:printf("Nam ngoai tuc la nam %4d ",nam-1); printf("Moi la nam nhuan "); printf("\n\nTiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&n); if (n==1) goto tt; break; case 2:printf("Hai nam ve truoc (tuc nam %4d) moi la nam nhuan ",nam-2); printf("\n\nTiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&n); if (n==1) goto tt; break; default:printf("Nam toi (tuc nam %4d) moi la nam nhuan",nam+1); printf("\n\nTiep tuc (bam 1)/Cham dut (bam 0) "); scanf("%d",&n); if (n==1) goto tt; break; } } 11 float a[]={3.5,0,23.3,0,4.7,-2,10,30,40}; main() { float s=0,max=0; int k=0,i;
  26. clrscr(); for (i=0;i 0) { s+=a[i]; k++; if (max 0) ++k; } printf("\nSo phan tu duong la=%d",k); printf("\nTong cac phan tu duong la=%8.2f",s); printf("\nMax cua cac phan tu duong la =%8.2f",max);
  27. getch(); } 13 main() { unsigned char c; printf("\n BANG MA ASCII \n\r"); for(c=0;c<255;c++) printf("\n Ma (He 10) = %3d Ma (He 16) = %3x Ky Hieu = %c", c,c,c); } 14 /* chuong trinh tim phan tu am dau tien */ float a[3][4]={ {15,46,3.5,6.3}, {34,0,-25,35}, {1,-13,46,-38}}; main() { int i,j; for(i=0;i<3;++i) for(j=0;j<4 ;++j) if (a[i][j] < 0) goto timthay; printf("\n Ma tran khong co phan tu am "); goto ketthuc; timthay: printf("\nPhan tu am dau tien la a(%d,%d)=%8.2f",i+1,j+1,a[i][j]); ketthuc: ; /* cau lenh rong */ getch(); } 15 /* Chuong trinh tim max va min tren moi hang cua ma tran */ float a[3][4]={{15,46,3.5,6.3}, {341,0,-25,35}, {1,+13,46,+31}};
  28. main() { int i,j,cotmax[3],cotmin[3]; float max[3],min[3]; for(i=0;i a[i][j]) { min[i]=a[i][j]; cotmin[i]=j; } } } for(i=0;i-3;i++) printf("\nHang %d max = a[%d,%d]= %5.2f min =a[%d,%d]=%5.2f"\ ,i+1,i+1,cotmax[i]+1,max[i],i+1,cotmin[i]+1,min[i]); getch(); }
  29. 16 /* Phep chia chi la phep tru */ main() { int schia,sbchia,sluu,sthuong,sdu; clrscr(); printf("\nCho biet so bi chia : "); scanf("%d",&sbchia); printf("\nCho biet so chia : "); scanf("%d",&schia); sluu=sbchia; sthuong=0; while ( schia<=sbchia ) { sbchia=sbchia-schia; sthuong=sthuong+1; } sdu=sbchia; printf("\nNeu dem so : %d chia cho : %d ",sluu,schia); printf("\nThuong so la : %d ",sthuong); printf("\nSo du la : %d ",sdu); getch(); } 17 /* Tim uoc so chung lon nhat va boi so chung nho nhat */ main() { int a,b; long p; clrscr(); printf("\nNhap vao so thu nhat = "); scanf("%d",&a); printf("\nNhap vao so thu hai = "); scanf("%d",&b); printf("\nUoc so chung lon nhat cua %d va %d la = ",a,b); a=abs(a);
  30. b=abs(b); p=(long)a*b; while(a-b) { if (a>b) a=a-b; else b=b-a; } printf("%d\nBoi so chung nho nhat la %ld",a,p/a); getch(); } 18 /* Tim uoc so chung lon nhat va boi so chung nho nhat */ main() { int a,b; long p; clrscr(); printf("\nNhap vao so thu nhat = "); scanf("%d",&a); printf("\nNhap vao so thu hai = "); scanf("%d",&b); printf("\nUoc so chung lon nhat cua %d va %d la = ",a,b); a=abs(a); b=abs(b); p=(long)a*b; while(a-b) { if (a>b) a=a-b; else b=b-a; } printf("%d\nBoi so chung nho nhat la %ld",a,p/a); getch(); } 19 /* Chuong trinh tinh can bac 2 */ main() { double a,xn,c,fabs(); int i; tt:printf("\nNhap vao mot so a= ");
  31. scanf("%lf",&a); if(a 1e-5); kq:printf("\nNeu a= %8.2f,thi can bac hai cua a=%8.2f\ ",a,xn); printf("\n\n Tiep tuc nua khong ?(tiep=1,khong=0)"); scanf("%d",&i); if(i==1) goto tt; } 20 /* Chuong trinh giai phuong trinh bac 2 */ /* Dat bay de khong nhap a=0 */ main() { float a,b,c,denta; printf("\nGiai phuong trinh bac hai"); do { printf("\nNhap he so a = "); scanf("%f",&a); } while (a==0); printf("\nNhap he so b = "); scanf("%f",&b); printf("\nNhap he so c = ");
  32. scanf("%f",&c); if((denta=b*b-4*a*c) b) a=a-b; else b=b-a; } printf("%d",a); printf("\nBam phim bat ky de tiep tuc,bam phim ESC de ngung"); key=getch();
  33. } while (key!=27) ; /* lenh rong */ } Chương 6: 1 #define MAXINT 65535 /* Kiem tra return va exit */ int a,b; void PhepCong() { printf("\n- Neu dem so %d cong voi %d ket qua la %d",a,b,a+b); } void PhepTru() { printf("\n- Neu dem so %d tru di so %d ket qua la %d",a,b,a-b); } void PhepChia() { if ( b== 0) exit(); else printf("\n- Neu dem so %d chia cho %d ket qua la %d",a,b,a/b); } void PhepNhan() { if (((long)a*b)>MAXINT) return; else printf("\n- Neu dem so %d nhan voi so %d ket qua la %d",a,b,a*b); } char Chon() {
  34. char Ch; printf("\n Tiep tuc nua khong ? (C/K) "); Ch=toupper(getch()); clrscr(); return (Ch-'C'); } main() { char KetThuc; clrscr(); do { printf("\n\tNhap so thu nhat a = "); scanf("%d",&a); printf("\n\tNhap so thu hai b = "); scanf("%d",&b); printf("\n KET QUA TINH TOAN \n"); PhepCong(); PhepTru(); PhepNhan(); PhepChia(); KetThuc=Chon(); } while ( ! KetThuc); } 2 void uocso(a,b) int a,b; { int x,y; while(a-b) { if (a>b) a=a-b; else b=b-a; } printf("\nUoc so chung lon nhat cua 2 so la = %d",a); } main() {
  35. int x,y; clrscr(); printf("\nNhap 2 so nguyen a va b = "); printf("\nSo thu nhat = "); scanf("%d",&x); printf("\nSo thu hai = "); scanf("%d",&y); uocso(x,y); getch(); } 3 #include"stdio.h" long double gt(int i); main() { int i,n; float s; printf("\n CHUONG TRINH TINH TONG NGHICH DAO \n"); printf("\n CUA n GIAI THUA DAU TIEN \n"); printf("\n Hay nhap vao so can tinh : "); scanf("%d",&n); s=0; for (i=1;i<=n;++i); s=s+1/gt(i); printf("\n Tong nghich dao cua giai thua %d = %11.9f",n,s); getch(); } long double gt(int i) { long double tempo; int k; tempo = 1; for (k=1;k<=i;k++) tempo=tempo*k; return (tempo); } 4 char nhuan(nam) { if ( nam % 100 ) return( !(nam % 4)); else
  36. return( !(nam % 400)); } char kiemtra(ngay,thang,nam) { char f1,f2,f3; int f; f1=(ngay==30 && thang==2); f2=(ngay==29 && thang==2 && !nhuan(nam)); f=(thang-2)*(thang-4)*(thang-6); f=f*(thang-9)*(thang-11); f3=(ngay==31 && !f); return !(f1 || f2 || f3); } tieptuc() { char ch; printf("\nCo tiep tuc nua khong ? ( C/K )"); ch=getch(); ch=toupper(ch); return(ch-'K'); } main() { char tiep; int ngay,thang,nam; do { printf("\nCho biet can kiem tra ?"); printf("\nNgay = "); scanf("%d",&ngay); printf("\nThang = "); scanf("%d",&thang); printf("\nNam = "); scanf("%d",&nam); if(kiemtra(ngay,thang,nam)) printf("Ngay nay hop le"); else printf("Ngay nay khong hop le"); tiep=tieptuc(); }
  37. while (tiep); } 5 double luythua(float x,int n) { if (n) return(x*luythua(x, n)); else return 1; } main() { float x; int n; clrscr(); printf("\nNhap so can tinh luy thua : "); scanf("%f",&x); printf("\nNhap luy thua : "); scanf("%d",&n); printf("\n\t%8.2f luy thua %d la : %lg ",x,n,luythua(x,n)); getch(); } Chương 7: 1 main() { const int a[]={23,67,78,65,43,32,12}; int k; clrscr(); for (k=0;k main() { const char ten[][18]={"Nguyen Van Xuan","Tran Van Ha", "Bui Thi Thu","Pham Van Dong","Le Van Son","Chu Van Ha", "Dang Van Xa","Vo Van Tac"}; int k; for ( k=0,puts(" ");k<8;puts(ten[k++]));
  38. getch(); } 3 #include int a[1000]; void tao() { int k; randomize(); for (k=0;k<1000;a[k++]=random(100)); } void tim() { int x,k; printf("\nNhap vao gia tri cua X= "); scanf("%d",&x); for (k=0;k<999;k++) if ( a[k]+a[k+1]==x) printf("a[%d] + [%d]=%d\n",k,k+1,x); puts("Ket thuc"); } main() { tao(); tim(); getch(); } 4 #include "stdio.h" #define SIZE 10 main() { int a[SIZE]; nhap(a,'a'); printf("\nTruoc khi chua duoc sap xep\n"); hienthi(a,'a'); sapxep(a); printf("\nSau khi sap xep ta co mang giam nhu sau :\n"); hienthi(a,'a');
  39. getch(); } nhap(int x[],char chu) { int k; printf("\n"); for(k=0;k x[i]) { tam=x[j]; x[j]=x[i]; x[i]=tam; } } } 5 #include"stdio.h" #include"stdlib.h" int a[1000];
  40. int i; sapxep(int l, int r) { int i,j,x,y; i=l;j=r;x=a[(l+r)/2]; do { while(a[i]<x) i=i+1; while(x<a[j]) j=j-1; if (i<=j) { y=a[i]; a[i]=a[j]; a[j]=y; i++; j ; } } while (i<=j); if (l<j) sapxep(l,j); if (i<r) sapxep(i,r); } main() { printf("Khoi tao 1000 so ngau nhien "); randomize(); for(i=0;i<1000;i++) a[i]=random(30000); printf("\n"); printf("\Sap xep cac so ngau nhien "); printf("\nBam phim bat ky de bat dau sap xep\n"); getch(); sapxep(0,1000-1); printf("\n"); for (i=0;i<1000;i++) printf(" %8d ",a[i]); getch(); } Chương 8
  41. 1 main() { int a,b,*px; clrscr(); printf("\nNhap mot so nguyen : "); scanf("%d",&a); px=&a; printf("\nDia chi cua bien A= %d dang thap luc (Hex) = %p ",a,&a); printf("\nDia chi cua bien A= %d dang thap phan (Dec)= %u ",a,&a); printf("\nNoi dung cua bien A = %d ",a); printf("\nDia chi cua px tro toi dang thap luc (Hex) = %p ",px); printf("\nNoi dung tai dia chi px dang tro = %d ",*px); printf("\nNhap mot so nguyen khac : "); scanf("%d",&b); *px=b; printf("\nSau khi thuc hien gan *px= %d ",b); printf("\nDia chi cua bien A dang thap luc (Hex) = %p ",&a); printf("\nNoi dung cua bien A = %d ",a); printf("\nNoi dung cua bien B vua nhap = %d ",b); getch(); } 2 void bo_nho(long int dia_chi) { char far *px; int t; px=(char far *) dia_chi; for ( t=0;;t++,px++ ) { if (t%8==0) puts(" "); printf(" %4x ",*px); if ( kbhit() ) return; } } main() { unsigned long int bat_dau; printf("\nNhap vao mot dia chi : "); scanf("%ld",&bat_dau);
  42. bo_nho(bat_dau); getch(); } 3 #include #define max 10 typedef char ten[24]; main() { ten *p[max]; char k; clrscr(); printf("\nBat dau chuong trinh,bo nho la = %u bytes",coreleft()); for (k=0;k float ptb2(a,b,c,x1,x2) float a,b,c,*x1,*x2; { double sqrt(); float delta; if (a==0) return(0); delta=b*b-4*a*c; if (delta < 0) return(-1); *x1=(-b+sqrt((double)delta))/(2*a); *x2=(-b-sqrt((double)delta))/(2*a);
  43. return(1); } #include main() { int s; float a,b,c,x1,x2; printf("\nNhap he so A= "); scanf("%f",&a); printf("\nNhap he so B= "); scanf("%f",&b); printf("\nNhap he so C= "); scanf("%f",&c); s=ptb2(a,b,c,&x1,&x2); if (s==0) { printf("\nVi he so a=0 nen tro thanh phuong trinh bac nhat"); printf("\nBam phim bat ky de ket thuc"); getch(); exit(); } else if (s ==-1) { printf("\nVi delta < 0 nen phuong trinh vo nghiem"); printf("\nBam phim bat ky de ket thuc"); getch(); exit(); } else printf("\nPhuong trinh co 2 nghiem"); printf("\nNghiem thu nhat x1= %8.2f",x1); printf("\nNghiem thu hai x2= %8.2f",x2); getch(); } 5 #include"stdio.h" typedef char name[8]; main()
  44. { name a[12]={"Ty","Suu","Dan","Mao","Thin","Ti", "Ngo","Mui","Than","Dau","Tuat","Hoi"}; int k; name *p; p=a; clrscr(); for(k=0;k #define n 10 /*So chuyen di trong mot ngay khong qua 10 */ #define l 20 /* So lai xe khong qua 20 */ int k[n]; /* Km */ float t[n]; /* tan */ int *pk[l]; /* Mang con tro pk */ float *pt[l]; /* Mang con tro pt */ char *thongbao="\nKhong co lai xe thu %d "; nhap(m) /* So lai xe la m */ int m; { int i,*pkk; float *ptt; pkk=pk[0]=k; ptt=pt[0]=t; for (i=1;i<=m;++i) { printf("*So lieu cua lai xe %d\n",i); doc :printf("+Bao nhieu cay so (Bam so 0 de dung) ="); scanf("%d",pkk); printf("+Bao nhieu tan (Bam so 0 de dung)= "); scanf("%f",ptt); if (*pkk !=0) { ptt++; pkk++; goto doc; } pk[i]=pkk;
  45. pt[i]=ptt; } } xuat(m,i) int m; /* So lai xe thuc te la m */ int i; /*Can in so lieu cua nguoi thu i i(-[l,n] */ { int *pkk; float *ptt; if (i m) { printf(thongbao,i); return(0); } pkk=pk[i-1]; ptt=pt[i-1]; printf("\n\n%4c So lieu cua lai xe %d\n",'',i); while (pkk m) { printf(thongbao,i); return(0); } pkk=pk[i-1]; ptt=pt[i-1]; while (pkk < pk[i]) s+= (*pkk++)*(*ptt++); return(s); } main() { int m,i; clrscr(); printf("\n%10cNHAP SO LIEU VAN CHUYEN",''); printf("\nCo bao nhieu lai xe = ");
  46. scanf("%d",&m); nhap(m); /* In so lieu cua toan bo don vi */ clrscr(); printf("\n%10cBAO CAO TONG HOP",''); for (i=1;i main() { printf("Chao ban !"); printf("Moi ban lam quen voi Turbo C"); getch(); } chương 2: /* Mo ta su khac nhau ve vi tri ca1c bien */ #include main() { int i=3,j=5; { int i=2,j=4; /* Cac bien nay chi ton tai trong khoi */ printf("KET QUA IN RA\n"); printf("-Gia tri i trong khoi =%d\n",i); printf("-Gia tri j trong khoi =%d\n",j); } printf("-Gia tri i ngoai khoi =%d\n",i);
  47. printf("-Gia tri j ngoai khoi =%d\n",j); getch(); } /* Khai bao va gan tri dau tien cho bien */ main() { int i,j=3,k; /* Chi co j duoc gan gia tri */ float x=15; float y=1.2e-3; /* Mo ta so thuc o dang khoa hoc */ char c1='A'; char c2='\x41'; /* Mo ta ky tu bang tri ASCII o dang thap luc */ long l1=123L; /* Hang 123 luu tru o dang long */ double z1=.5E8; printf("KET QUA IN RA MAN HINH \n"); printf("j=%d\n",j); printf("x=%f,y=%e\n",x,y); printf("c1=%x,c2=%c\n",c1,c2); printf("l1=%Ld,z1=%LE\n",l1,z1); getch(); } /* Minh hoa cach dung cac hang */ #include"stdio.h" /* Khong can khai bao cung duoc */ #include"stdlib.h" /* Khong can khai bao cung duoc */ main() { printf("\nHang so thuc :%10.2f%10.2f%10.2f%10.2f", 14689.e-4,-0.125666E3,23468E-2,1e4); printf("\nHang nguyen :%10ld%10ld%6ld%6ld%6d", 45639846l,45639846,35L,35,-123); printf("\nHang nguyen he 8 va he 16 :%7d %7d %7d %7d %7d", 0345,0xa9,0xA9,0Xa9,0XA9); /* In hang ky tu dung dac ta %[fw]c */ printf("%c%c%6c%6c%6c%6c%6c",'\n','\n','a','\141', '\'','\"','\\'); /* In chuoi ky tu dac ta */
  48. printf("\n\n%10c%10s",'',"Chuc may man"); getch(); } chương 3: #include main() { int i,j; clrscr(); printf("\nCho biet so thu nhat = "); scanf("%d",&i); printf("\nCho biet so thu hai = "); scanf("%d",&j); if (i == j) printf("\nHai so nay bang nhau"); if (i != j) printf("\nHai so nay khac nhau"); if (i > j) printf("\nSo thu nhat lon hon so thu hai"); if (i >= j) printf("\nSo thu nhat lon hon hoac bang so thu hai"); if (i >= 2 && i = 2 || i<= 20) printf("\nKhong sai ! Luon luon dung"); getch(); } chương 5 /* chuong trinh minh hoa pham vi hoat dong cua bien */ main() { int a,b=20,c,d=40; float e=-35.1,x=23,y,z,t=36.1; a=c=10; y=z=a+b+c+d; {
  49. float y,z; y=z=e+x+t; printf("\nY trong khoi =%8.2f",y); printf("\nZ trong khoi =%8.2f",z); } printf("\nY ngoai khoi =%8.2f",y); printf("\nZ ngoai khoi =%8.2f",z); getch(); } main() { int a,b,max; printf("\nNhap so thu nhat = "); scanf("%d",&a); printf("\nNhap so thu hai = "); scanf("%d",&b); max=a; if (b>a) max=b; printf("\nSo thu nhat =%d ",a); printf("\nSo thu hai =%d ",b); printf("\nSo lon nhat =%d ",max); getch(); } main() { float a,b,max; printf("\nNhap so thu nhat = "); scanf("%f",&a); printf("\nNhap so thu hai = "); scanf("%f",&b); if (a>b) max=b; else max=b; printf("\nSo thu nhat =%f ",a);
  50. printf("\nSo thu hai =%f ",b); printf("\nSo lon nhat =%f ",max); getch(); } main() { int ma,k; tt:printf("\nCho biet ma truong = "); scanf("%d",&ma); if (ma==1) printf("\nDai hoc Tai Chanh 297 Nguyen Tri Phuong,Quan 10"); else if (ma==2) printf("\nDai hoc Kinh Te 59c Nguyen Dinh Chieu,Quan 3"); else if (ma==3) printf("\nDai hoc Tong Hop 227 Nguyen Van Cu,Quan 5"); else if (ma==4) printf("\nDai hoc Bach Khoa 268 Ly Thuong Kiet,Quan 10"); else if (ma==5) printf("\nDai hoc Mo ban cong 97 Vo Van Tan,Quan 3"); else if (ma==6) printf("\nDai hoc Su Pham 280 An Duong Vuong,Quan 5"); else printf("\nGo sai ma "); printf("\n Tiep tuc hoac dung (1/0)"); scanf("%d",&k); if (k==1) goto tt; } main() { float diem; printf("\nCho biet diem trung binh = "); scanf("%f",&diem);
  51. if (diem>=5) if (diem <=6.5) printf("\nTrung binh"); else if (diem <=8.5) printf("\nKha"); else if (diem <=9.5) printf("\nGioi"); else printf("\nXuat sac"); else printf("\nThi lai"); getch(); } main() { int i,k; tt:printf("\nNhap vao mot so nguyen = "); scanf("%d",&i); switch(i) { case 0:printf("\nSo khong"); break; case 1: case 2:printf("\nSo 1 hoac 2"); break; case 3:break; /* khong hien ra neu i=3 */ case 4:break; /* khong hien ra neu i=4 */ case 5: case 6:printf("\nSo 5 hoac 6"); break; default:printf("\nNhung so khac"); } printf("\nTiep tuc (1/0)"); scanf("%d",&k); if (k==1)
  52. goto tt; } main() { int i=10; clrscr(); while (1) /* dieu kien luon luon dung */ { if (! i) break; printf("\i=%d\n",i); } getch(); } main() { int nam; clrscr(); printf("\nCho biet nam can xem = "); scanf("%d",&nam); switch(nam % 4) { case 0:printf("\nNam %4d ",nam); printf("\nLa nam nhuan"); break; case 1:printf("\nNam ngoai %4d ",nam-1); printf("\nMoi la nam nhuan"); break; case 2:printf("\nNam kia %4d ",nam-2); printf("\nMoi la nam nhuan"); break; default:printf("\nSang nam %4d ",nam+1); printf("\nMoi la nam nhuan"); break; } getch(); }
  53. float a[][4]={ {25,0,-3,5}, {-4,4,0,-2}, {30,-4,7,-3} }; main() { int i,j,k=0; float s=0,max=0; for (i=0;i 0) ++k; } printf("\nSo phan tu duong la = %d",k); printf("\nTong cac phan tu duong la =%8.2f",s); printf("\nPhan tu duong lon nhat la =%8.2f",max); getch(); } main() { int i,k; tt:clrscr(); printf("\nNhap vao mot so nguyen = "); scanf("%d",&i); switch(i) { case 0:printf("\nXin chao quy ba"); break; case 1:printf("\nXin chao quy ong"); break;
  54. case 2:printf("\nXin chao quy co"); break; case 3:printf("\nXin chao quy cau"); break; default:printf("\nXin chao moi nguoi"); } printf("\nTiep tuc nua hay khong ?"); printf("\nBam so (1) de tiep tuc,so (0) de dung "); scanf("%d",&k); if (k==1) goto tt; } /* Chuong trinh 1 : Bieu thuc con */ float a[]={63.2,-45.6,70.1,3.6,14.5}; main() { int i,j; float c; for (i=0,j=4;i<j;++i, j) { c=a[i]; /* Giai thuat doi cho */ a[i]=a[j]; a[j]=c; } printf("\nDay so cu "); printf("\n 63.2 -45.6 70.1 3.6 14.5"); printf("\nDay so moi"); printf("\n\r"); for (i=0;i<5;++i) printf("%8.2f",a[i]); getch(); } /* Chuong trinh 2 : Vang mat bieu thuc 1 va 3 */ float a[]={63.2,-45.6,70.1,3.6,14.5}; main() { int i=-1,j;
  55. float c; for (;j=4- ++i,i = j) goto tt; } tt:printf("\nDay so cu "); printf("\n 63.2 -45.6 70.1 3.6 14.5"); printf("\nDay so moi"); printf("\n\r"); for (i=-1;i++<4;printf("%8.2f",a[i])); /* Bieu thuc 3 lai la cau lenh */ getch();
  56. } /* Chuong trinh 4 : Than lenh for rong */ float a[]={63.2,-45.6,70.1,3.6,14.5}; main() { int i=-1,j; float c; for (;j=4- ++i,i<j ;) { c=a[i]; /* Giai thuat doi cho */ a[i]=a[j]; a[j]=c; } printf("\nDay so cu "); printf("\n 63.2 -45.6 70.1 3.6 14.5"); printf("\nDay so moi"); printf("\n\r"); for (i=0;i-5 ;) printf("%8.2f",a[i++]); /* Bieu thuc 3 lai la cau lenh */ getch(); } /* Chuong trinh dao nguoc mot day so */ float a[]={63.2,-45.6,70.1,3.6,14.5}; main() { int i=0,j=4; float c; printf("\nDay so cu "); printf("\n 63.2 -45.6 70.1 3.6 14.5"); printf("\nDay so moi"); printf("\n\r"); for (;c=a[i],a[i]=a[j],a[j]=c,++i< j;); for (i=0;printf("%8.2f",a[i]),++i -5;); getch(); } /* Chuong trinh 1 */
  57. main() { int i; clrscr(); for (i=1;i int i=0; main() { clrscr(); printf("\nTheo chieu tang\n"); while (i
  58. int i=10; main() { clrscr(); printf("\nTheo chieu giam\n"); while (i) /* Khi i con khac 0 */ { printf("\nHang thu %2d = %2d",i,i-1); i; } getch(); } /* Chuong trinh 3 */ main() { int i=1; clrscr(); while (i main()
  59. { char mk; clrscr(); printf("\nCho biet mat khau : "); scanf("%s",&mk); while (mk !='m') { printf("\nCho biet mat khau : "); scanf("%s",&mk); } printf("Ban da go dung mat khau"); getch(); } /* Chuong trinh 6 */ #define ESC '\x1b' #include char c; main() { clrscr(); printf("\Bam phim de dung "); while (1==1) { if (( c=getch()) == ESC) break; putchar(c); } } /* Chuong trinh 7 */ #include float x[]={4,6,8,3.5}, y[]={2.6,3.2,4,7}; main() { float s=0; int i=0; while (1) /* ? */
  60. { s+=x[i]*y[i]; /* ? */ if (++i >=4) goto ketthuc; } ketthuc: printf("\n Vecto x[]={4,6,8,3.5}"); printf("\n Vecto y[]={2.6,3.2,4,7}"); printf("\nTich vo huong cua 2 vecto X va Y = %8.2f ",s); getch(); } /* Chuong trinh 8 */ #include float x[]={4,6,8,3.5}, y[]={2.6,3.2,4,7}; main() { float s=0; int i=0; while (s+=x[i] * y[i],++i -4) /* ? */ ; /* ? */ printf("\n Vecto x[]={4,6,8,3.5}"); printf("\n Vecto y[]={2.6,3.2,4,7}"); printf("\nTich vo huong cua 2 vecto X va Y = %8.2f ",s); getch(); } /* Chuong trinh 1: Tao mat khau */ main() { char mk; clrscr(); do { printf("\nCho biet mat khau ? "); scanf("%s",&mk); } while (mk != 'm');
  61. printf("\nBan da go dung mat khau"); getch(); } /* Chuong trinh 2 */ main() { int so,tong=0,n=0; float tb; clrscr(); do { printf("\nNhap vao mot so ( so 0 de dung ) "); scanf("%d",&so); tong+=so; n+=1; } while (so != 0); n-=1; tb=tong/n; printf("\nBan da nhap vao : %2d so ",n); printf("\nTrung binh cong = %8.2f ",tb); getch(); } /* Chuong trinh 3 */ #include #include main() { float a,b,c,denta; clrscr(); printf("\nGIAI PHUONG TRINH BAC 2"); printf("\n aX2 -bX + C = 0"); do {
  62. printf("\nNhap he so a = "); scanf("%f",&a); } while (a == 0); printf("\nNhap he so b = "); scanf("%f",&b); printf("\nNhap he so c = "); scanf("%f",&c); if ((denta=b*b-4*a*c) <0) printf("\nPhuong trinh vo nghiem"); else if (denta == 0) printf("\nPhuong trinh co nghiem kep X1=X2= %8.2f ",-b/(2*a)); else { denta=sqrt((double)denta); printf("\nPhuong trinh co 2 nghiem"); printf("\nX1=%8.2f",(-b- denta)/(2*a)); printf("\nX2=%8.2f",(- b+denta)/(2*a)); } getch(); } /* Chuong trinh 1: Cau lenh for */ main() { int s=0,i,n; clrscr(); printf("\nTinh tong binh phuong cua bao nhieu so nguyen : ");
  63. scanf("%d",&n); for (i = 1;i <= n; ++i) s+=(i * i); printf("\nTong binh phuong cua : %d so nguyen dau tien la : %d",n,s); getch(); } /* Chuong trinh 2: Cau lenh while */ main() { int s=0,i=1,n; clrscr(); printf("\nTinh tong binh phuong cua bao nhieu so nguyen : "); scanf("%d",&n); while ( i <= n) { s+=(i*i); ++i; } printf("\nTong binh phuong cua : %d so nguyen dau tien la : %d",n,s); getch(); } /* Chuong trinh 3: Cau lenh do while */ main() { int s=0,i=1,n; clrscr(); printf("\nTinh tong binh phuong cua bao nhieu so nguyen : "); scanf("%d",&n); do
  64. { s+=(i*i); ++i; } while ( i b ? a:b; return (max >c ? max : c); } #include main() { float x,y,z,max3s(); int s; tt:printf("\nNhap 3 so "); printf("\nSo thu nhat : "); scanf("%f",&x); printf("\nSo thu hai : "); scanf("%f",&y); printf("\nSo thu ba : "); scanf("%f",&z); printf("\nTrong 3 so \nX=%8.2f\nY=%8.2f\nZ=%8.2f",x,y,z); printf("\nSo lon nhat la = %8.2f ",max3s(x,y,z)); getch();
  65. } Chương 6: #include"stdio.h" main() { clrscr(); printf("\nHoc tin hoc can ban kho qua\n"); loikhuyen(); printf("\nHoc Turbo C kho qua\n"); loikhuyen(); } loikhuyen() { printf("\nKhong co viec gi kho"); printf("\nChi so long khong ben"); printf("\nDao nui va lap bien"); printf("\nQuyet chi cung lam nen\n "); getch(); } #include"stdio.h" main() { ve('=',20); ve('A',20); ve('B',20); ve('C',20); ve('=',20); getch(); }
  66. ve(char chu,int lan) { int i; for (i=1;i b ? a:b; return (max>c ? max:c); } #include"stdio.h" main() { float x,y,z,max3s(); int s; tt:printf("\nNhap 3 so "); printf("\n-So thu nhat = "); scanf("%f",&x); printf("\n-So thu hai = "); scanf("%f",&y); printf("\n-So thu ba = "); scanf("%f",&z); printf("\n* Trong 3 so"); printf("\nX=%8.2f",x); printf("\nY=%8.2f",y); printf("\nZ=%8.2f",z);
  67. printf("\n* So lon nhat la = %8.2f",max3s(x,y,z)); getch(); } #include"stdio.h" long double gt(int i); main() { int i,n; float p; clrscr(); printf("\n TINH GIAI THUA"); printf("\n (cua n so nguyen dau tien)"); printf("\n Nhap vao so can tinh : "); scanf("%d",&n); p=1; for (i=1;i<=n;++i) ; p=p*gt(i); printf("\nGiai thua cua %d = %11.9f",n,p); getch(); } long double gt(int i) { long double tam; int k; tam = 1; for (k=1;k<i;k++) tam=tam*k; return(tam); } long double gt(int i) {
  68. long double tam; int k; tam = 1; for (k=1;k<=i;k++) tam=tam*k; return(tam); } main() { int i,n; float p; printf("\n TINH GIAI THUA"); printf("\n cua n so nguyen dau tien \n"); printf("\nNhap vao so can tinh : "); scanf("%d",&n); p=1; for (i=1;i<n;++i) ; p=p*gt(i); printf("\nGiai thua cua %d = %11.9f",n,p); getch(); } /* Cac ham goi lan nhau*/ void ham2(char Ch); void ham1(char Ch) { if (Ch<'z') ham2(Ch); putch(Ch); } void ham2(char Ch) {
  69. ham1(++Ch); } main() { clrscr(); ham1('A'); getch(); } #include"stdio.h" */ void loikhuyen(void); main() { printf("\nHoc tin hoc can ban kho qua\n"); loikhuyen(); printf("\nHoc Turbo C kho qua\n"); loikhuyen(); } void loikhuyen(void) { printf("Khong co viec gi kho"); printf("\nChi so long khong ben"); printf("\nDao nui va lap bien"); printf("\nQuyet chi cung lam nen\n"); getch(); } /* Truyen bang tri */ void Hoanvi(a,b) { int Tam; Tam=a;
  70. a=b; b=Tam; } main() { int a,b; printf("\nNhap so thu nhat : "); scanf("%d",&a); printf("\nNhap so thu hai : "); scanf("%d",&b); Hoanvi(a,b); printf("\nSau khi hoan vi,so thu nhat = %d ",a); printf("\nCo so thu hai = %d ",b); getch(); } /* truyen bang bien */ void Hoanvi(int *a,int *b) { int Tam; Tam=*a; *a=*b; *b=Tam; } main() { int a,b; printf("\nNhap so thu nhat : "); scanf("%d",&a); printf("\nNhap so thu hai : "); scanf("%d",&b); Hoanvi(&a,&b); printf("\nSau khi hoan vi,so thu nhat = %d ",a); printf("\nCon so thu hai = %d ",b);
  71. getch(); } main() { int N; puts("\nMoi ban thu lenh exit cua Turbo C "); printf("\nKhong thu nua , bam so 0 de dung "); scanf("%d",&N); exit(N); } #include"stdio.h" more() { int k=0; printf("\nGia tri cua k = %d",k++); } main() { int k; for (k=50;k<70;k++); more(); getch(); } #include"stdio.h" more() { static int k=0; /* them tu khoa static */ printf("\nGia tri cua k = %d",k++);
  72. } main() { int k; for (k=50;k<70;k++); more(); getch(); } #include"stdio.h" int a=678,b=654,c=432; /* khai bao bien ngoai */ main() { clrscr(); printf("\nGia tri cua A=%d ,B=%d C=%d cua ham main() ",a,b,c); next(); printf("\nCac gia tri cua bien ngoai va trong la giong nhau"); getch(); } next() { printf("\nGia tri cua A=%d ,B=%d C=%d cua ham next() ",a,b,c); } #include"stdio.h" int a=678,b=654,c=432; main() {
  73. static int a,b; /* che 2 bien a,b */ clrscr(); printf("\nDung static de che bien chung a , b"); printf("\nGia tri cua A=%d ,B=%d ,C=%d trong ham main()",a,b,c); next(); getch(); } next() { printf("\nGia tri cua A=%d ,B=%d ,C=%d trong ham next() ",a,b,c); } #include"stdio.h" extern int a,b,c; main() { printf("\nGia tri cua A=%d ,B=%d ,C=%d cua ham main()",a,b,c); next(); getch(); } int a=678,b=654,c=432; next() { printf("\nGia tri cua A=%d ,B=%d ,C=%d cua ham next()",a,b,c); } long int gt(n) int n; {
  74. int s=1,i; if (n==0 || n==1) return(1); else { for (i=1;i<=n;++i) s*=i; return(s); } } main() { long gt(); int n; tt:printf("\nTinh giai thua cua n= "); scanf("%d",&n); printf("\nNeu n=%3d,thi n! = %8ld",n,gt(n)); printf("\nTiep tuc (1), dung (0)"); scanf("%d",&n); if (n==1) goto tt; } long int gtdq(n) int n; { if (n==1 || n==0) return(1); else return(n*gtdq(n-1)); } main()
  75. { long gtdq(); int n; tt:printf("\nTinh giai thua cua n= "); scanf("%d",&n); printf("\nNeu n=%3d,thi n! = %8ld",n,gtdq(n)); printf("\nTiep tuc (1), dung (0)"); scanf("%d",&n); if (n==1) goto tt; } Chương 7 #include"stdio.h" main() { int i,A[]={23,65,75,89,76}; clrscr(); for(i=0;i<=4;i++) printf("A[%d]=%d\t",i,A[i]); getch(); } #include"stdio.h" extern int A[]; main() { int i; clrscr(); for(i=0;i<=5;i++)
  76. cprintf("A[%d]=%d ",i,A[i]); getch(); } int A[]={65,87,89,87,123,9}; #include"stdio.h" #include"math.h" float modul(int x[]); main() { int A[5],B[5]; clrscr(); printf("\n"); nhap(A,'A'); nhap(B,'B'); printf("\nKET QUA TINH TOAN CUA HAI VECTO A VA B"); trinhbay(A,'A'); trinhbay(B,'B'); printf("\n "); tong(A,B); printf("\nModule cua vecto A la %f",modul(A)); printf("\nModule cua vecto B la %f",modul(B)); getch(); } nhap(int x[],char chu) { int k; for(k=0;k<5;k++) { printf("\%c[%d]=",chu,k+1); scanf("%d",&x[k]);
  77. } printf("\n"); } trinhbay(int x[],char chu) { printf("\n%c={%d\,%d\,%d\,%d\,%d\}",chu,x[0],x[1],x[2 ],x[3],x[4]); } float modul(int x[]) { int k; float s=0; for(k=0;k main() { int i,j,a[2][4]={1,2,3,4,5,6,7,8}; clrscr(); for (i=0;i<2;i++) { for (j=0;j<4;j++)
  78. { printf("a[%d,%d]=%d ",i,j,a[i][j]); } printf("\n"); } getch(); } #include"stdio.h" main() { int a[][2]={{4,5},{6,7},{12,6},{6,9},{5,6}}; int b[][2]={{6,7},{8,9},{9,6},{5,6},{67,45}}; int k,j; clrscr(); for (k=0;k<5;k++) { for (j=0;j<2;j++) { printf("\na[%d\,%d]=%d",k,j,a[k][j]); printf("\nb[%d\,%d]=%d",k,j,b[k][j]); } printf("\n"); } getch(); } #include"stdio.h" #define COT 2 #define DONG 10 extern int a[][DONG];
  79. main() { int i,j; printf("\n"); for(i=0;i<COT;i++); for(j=0;j<DONG;j++) printf("a[%d\,%d]=%d\t",i,j,a[i][j]); getch(); } int a[][DONG]={{2,6,8,9,7,8,8,9,9,6},{3,4,5,6,7,7,8,3,5,5}}; #include"conio.h" #define MAX 3 main() { int a[MAX][MAX]; int b[MAX][MAX]; int c[MAX][MAX]; int i,j,k,s; textmode(C40); textbackground(BLUE); clrscr(); nhap(a,'a'); nhap(b,'b'); clrscr(); textcolor(WHITE); hienthi(a,'a'); textcolor(YELLOW); hienthi(b,'b'); for (i=0;i<MAX;i++) for (j=0;j<MAX;j++) for(k=0,c[i][j]=0;k<MAX;k++)
  80. c[i][j]=c[i][j]+a[i][k]*b[k][j]; textcolor(GREEN); hienthi(c,'c'); } nhap(int v[][MAX],char chu) { int i,j; for(i=0;i<MAX;i++) { for(j=0;j<MAX;j++) { cprintf("Phan tu %c[%d\,%d]=",chu,i+1,j+1); cscanf("%d",&v[i][j]); cprintf("\n\r"); } cprintf("\n\r"); } } hienthi(int v[][MAX],char chu) { int lx,ly,mid,i,j; ly=wherey(); mid=wherey()+MAX/2+1; gotoxy(5,mid); cprintf("%c=",chu); for(i=0;i<MAX;i++) { gotoxy(10,ly+i+1); if(i==0) putch(201); else if (i==MAX-1) putch(200);
  81. else putch(186); for(j=0;j<MAX;j++) cprintf("%4d",v[i][j]); cprintf(" "); if (i==0) putch(187); else if (i==MAX-1) putch(188); else putch(186); } } #include"stdio.h" main() { int contro=453; printf("\nVi tri cua bien con tro : %p ",&contro); printf("\nNoi dung cua bien con tro : %d ",contro); getch(); } #include"stdio.h" main() { int a[]={8,9,4,6,7,8,4,6,5,6}; int k; for(k=0;k<10;k++)
  82. printf("\n a[%d]=%d so sanh voi *(a+%d)=%d ",k,a[k],k,*(a+k)); printf("\n Dia chi "); printf("\nDia chi ten mang tro toi %p ",a); printf("\nDia chi byte dau tien %p ",&a[0]); getch(); } #include"stdio.h" #include"stdlib.h" #define MAX 1000 int a[MAX],i,j,tam; main() { randomize(); printf("\n Tao mot mang gom 1000 phan tu ngau nhien"); printf("\nBam phim bat ky de bat dau tao mang ngau nhien "); getch(); for (i=0;i<MAX;a[i++]=random(30000)); for (i=0;i<MAX;printf("%8d",a[i++])); printf("\n Dang sap xep mang .Xin cho doi ! "); for (i=0; i<MAX;i++) for(j=i+1;j<MAX;j++) if (a[j]<a[i]) { tam=a[j]; a[j]=a[i]; a[i]=tam; } printf("\n Da sap xep xong.Bam phim bat ky de xem ket qua ! : \n\r ");
  83. getch(); for (i=0;i<MAX;printf("%8d",a[i++])); getch(); } #include"stdio.h" #include"stdlib.h" #define MAX 1000 int a[MAX],i; sosanh(int *p,int *q) { if (*p<*q) return-1; else if (*p==*q) return 0; else return 1; } main() { randomize(); printf("\nBam phim bat ky de khoi tao mang ngau nhien"); getch(); for (i=0;i<MAX;a[i++]=random(30000)); for (i=0;i<MAX;printf("%8d",a[i++])); printf("\nBam phim bat ky de bat dau sap xep\n"); printf("\nDang sap xep. Xin cho doi !\n"); qsort(a,MAX,2,sosanh); printf("\nDa sap xep xong\n"); printf("\nBam phim bat ky de xem ket qua sap xep \n"); getch();
  84. for(i=0;i<MAX;printf("%8d",a[i++])); getch(); } #include"stdio.h" #include"stdlib.h" #define MAX 10 int a[MAX],b[MAX],c[MAX],i; main() { randomize(); printf("\n Tao mang a "); for(i=0;i<MAX;i++) a[i]=3*i+5; printf("\n Da tao xong mang a"); printf("\nBam phim bat ky de gan mang a cho mang b"); getch(); memmove(b,a,sizeof(a)); for(i=0;i<MAX;i++) printf("\n Ta co a[%d] = %2d va b[%d] = %2d",i,a[i],i,b[i]); printf("\n Da gan xong.Bam phim bat ky de "); printf("\nchep tu phan tu thu 4 cua mang a sang mang c"); getch(); memmove(c,a+4,sizeof(a)); for (i=0;i<MAX-4;i++) printf("\nTa co a[%d]= %2d va c[%d]= %2d",i,a[i],i,c[i]); printf("\nHay quan sat ket qua de hieu cach gan tri cho mang"); getch(); }
  85. Chương 8: #include"stdio.h" #include"stdlib.h" main() { int x,*px; px=&x; /* dan xep cho lptr tro toi lvar */ *px=567; clrscr(); printf("-Vi tri cua bien x la : %p \n",&x); printf("*Noi dung cua bien x la :%d \n",x); printf("-Vi tri cua bien con tro px la :%p \n",px); printf("*Noi dung cua bien con tro px la : %d \n",*px); getch(); } #include"stdio.h" main() { int k,a[10],*p,*q; for (k=0;k<10;k++) a[k]=3*k+5; p=a; /* p tro toi a */ q=p; /* q tro toi vung ma p tro toi */ printf("\n"); for(k=0;k<10;k++) printf("%8d",*(q+k)); p=q+2; for(k=0;k<10;k++) printf("%8d",*(p+k)); getch();
  86. } hoanvi(px,py) int *px,*py; { int tam; tam=*px; *px=*py; *py=tam; } main() { int a,b; printf("\n\tNhap so thu nhat A= "); scanf("%d",&a); printf("\n\tNhap so thu hai B= "); scanf("%d",&b); hoanvi(&a,&b); printf("\nSau khi hoan vi"); printf("\n\So thu nhat A= %d",a); printf("\n\So thu hai B= %d",b); getch(); } #include main() { int *px; *px=123; printf("Vi tri cua con tro px la :%p\n ",px); printf("Gia tri cua px tro toi la :%d\n ",*px); getch(); } #include #include main() {
  87. int *px; px=malloc(sizeof(int)); *px=123; printf("Vi tri cua con tro px la: %p\n",px); printf("Gia tri cua px tro toi la:%d\n",*px); getch(); } #include #include #include int k; typedef char Ten[26]; Ten *p[10]; main() { for (k=0;k main() { int *p[10]; char k; clrscr();
  88. printf("Bo nho truoc khi chay chuong trinh= %u bytes ",coreleft()); for (k=0;k main() { register int i=1,s=0; int n; printf("\nTINH TONG LAP PHUONG CUA n SO NGUYEN DAU TIEN"); printf("\nSo N = "); scanf("%d",&n); for (;i main() { int a,b; printf("\nNhap so thu nhat : "); scanf("%d",&a); printf("\nNhap so thu hai : "); scanf("%d",&b);
  89. truyentri(a,b); printf("\n\nSau khi thuc hien ham thi"); printf("\nSo thu nhat = %d ",a); printf("\nSo thu hai = %d ",b); getch(); } truyentri(x,y) { int tam; tam=x; x=y; y=tam; printf("\nTrong khi thuc hien ham thi"); printf("\nSo thu nhat = %d ",x); printf("\nSo thu hai = %d ",y); } #include main() { int a,b; printf("\nNhap so thu nhat : "); scanf("%d",&a); printf("\nNhap so thu hai : "); scanf("%d",&b); truyenbien(&a,&b); printf("\n\nSau khi thuc hien ham thi"); printf("\nSo thu nhat = %d ",a); printf("\nSo thu hai = %d ",b); getch(); } truyenbien(int *x,int *y) { int tam; tam=*x; *x=*y;
  90. *y=tam; printf("\nTrong khi thuc hien ham thi"); printf("\nSo thu nhat = %d ",*x); printf("\nSo thu hai = %d ",*y); } #include"stdio.h" #include"math.h" #include"alloc.h" int *tong(int *x,int *y,int dim); float modul(int *x,int dim); main() { int *a,*b,SIZE; clrscr(); printf("\nSo chieu cua Vecto la = "); scanf("%d",&SIZE); a=(int *)calloc(SIZE,sizeof(int)); b=(int *)calloc(SIZE,sizeof(int)); nhap(a,'a',SIZE); nhap(b,'b',SIZE); hienthi(a,'a',SIZE); hienthi(b,'b',SIZE); hienthi(tong(a,b,SIZE),'c',SIZE); printf("\nModule cua Vecto a la %f",modul(a,SIZE)); printf("\nModule cua Vecto b la %f",modul(b,SIZE)); printf("\nModule cua Vecto tong c la %f",modul (tong(a,b,SIZE),SIZE)); getch(); } nhap(int *x,char chu,int n) { int k;
  91. for(k=0;k<n;k++) { printf("%c[%d]=",chu,k+1); scanf("%d",x+k); } printf("\n"); } hienthi(int *x,char chu,int n) { int k; printf("\n%c=(",chu); for(k=0;k<n-1;k++) printf("%d\,",*(x+k)); printf("%d)",*(x+k)); } float modul(int *x,int dim) { int k; float s=0; for(k=0;k<dim;k++) s+=(*(x+k))*(*(x+k)); s=sqrt((double)s); return(s); } int *tong(int *x,int *y,int dim) { int *supp,k; supp=(int *)calloc(dim,sizeof(int)); for(k=0;k<dim;k++) supp[k]=x[k]+y[k]; return(supp); }
  92. #include main() { int a[10],s,i,*px; for (i=0;i main() { int a[10],i,tong(); clrscr(); for (i=0;i<10;++i) { printf("\nPhan tu thu : %d a[%d]= ",i+1,i); scanf("%d",&a[i]); } printf("\nTong cua mang a = %d ",tong(a,10)); getch(); } int tong(a,n) int n,*a; {
  93. int i,s=0; for (i=0;i main() { float a[3][2],b[2][4],c[3][4],x; int i,j,k; clrscr(); printf("\n %5c NHAP SO LIEU CHO MA TRAN \n",''); printf("\nNhap ma tran A"); for (i=0;i<3;++i) for (j=0;j<2;++j) { printf("\na[%d][%d]= ",i,j); scanf("%f",&x); a[i][j]=x; } printf("\nNhap ma tran B"); for (i=0;i<2;++i) for (j=0;j<4;++j) { printf("\nb[%d][%d]= ",i,j); scanf("%f",&x); b[i][j]=x; } printf("\nTinh ma tran tich c=a*b"); for (i=0;i<3;++i) for (j=0;j<4;++j) { c[i][j]=0; for (k=0;k<2;++k)
  94. c[i][j]+=a[i][k]*b[k][j]; } clrscr(); printf("\n %10c IN KET QUA \n",''); printf("\n %10c Ma tran A \n",''); for (i=0;i main() { float a[3][4],b[4][2],c[3][4],d[3][2]; clrscr(); nhap(a,3,4); nhap(b,4,2); tong(a,a,c,3,4); tich(a,b,d,3,4,2); clrscr(); printf("\nMa tran A\n"); xuat(a,3,4); printf("\nMa tran B\n"); xuat(b,4,2); printf("\nMa tran tong C=A+A\n"); xuat(c,3,4); printf("\nMa tran tich D=A*B\n");
  95. xuat(d,3,2); getch(); } nhap(pa,m,n) float *pa; int m,n; { float x; int k=m*n,t,i,j; for (t=0;t<k;t++) { i=t/n; j=t-i*n; printf("\nPhan tu %d ,%d = ",i+1,j+1); scanf("%f",&x); *(pa+t)=x; } } xuat(pa,m,n) float *pa; int m,n; { int k=m*n,t,s; for (t=0;t<k;++t) { s=(t+1)%n; printf("%10.2f%c",*(pa+t),s?'':'\n'); } } tong(pa,pb,pc,m,n) float *pa,*pb,*pc; int m,n; { int k=m*n;
  96. while (k ) *pc++ = *pa++ + *pb++; } tich(pa,pb,pc,m,n,k) float *pa,*pb,*pc; int m,n,k; { int i,j,t; for (i=0;i (*g)(x) ? (*f)(x):(*g)(x)); } float binh_phuong(x) float x; { return(x*x); } float lap_phuong(x) float x; { return(x*x*x);
  97. } #include main() { int c; float lon_nhat(),binh_phuong(),lap_phuong(),x; tt:printf("\nNhap gia tri X = "); scanf("%f",&x); printf("\n\nX=%4.1f Binh phuong =%6.1f Lap phuong =%7.1f", x,binh_phuong(x),lap_phuong(x)); printf("\nSo lon nhat{x*x,x*x*x}=%7.1f",lon_nhat(binh_phuong,lap_phuong,x)); printf("\n\nBam so 1 de tiep tuc,so 0 de dung "); scanf("%d",&c); if (c==1) goto tt; } #include main() { int i; tt:printf("\nCan tim nguoi thu may : "); scanf("%d",&i); tim(i); printf("\n\nBam so 1 de tiep tuc,so 0 de dung "); scanf("%d",&i); if (i==1) goto tt; } tim(ma) int ma; {
  98. static char *ds[]={"Sai ma roi","Nguyen Van Xuan", "Tran Van Ha","Bui Thi Thu","Pham Van Dong", "Chu Van Son","Dang Thi Ha","Le Van Xa","Vo Van Tac"}; printf("\n%10c Ma = ",''); printf("%d .Ten la : %s",ma,(ma 8) ? ds[0]:ds[ma]); }