printf(quot;Hello HCMUT 1411875 quot;); phan 1 printf(quot;%d quot;, 2014); printf(quot;%e %f %E quot;, 3.14159, 0.00057326, 3.14159); printf(quot;%c quot;, 39;A39;); printf(quot;%s quot;, quot;Dai hoc Bach Khoaquot;); printf(quot; DAI HOC BACH KHOA quot;); printf(quot; quot;); yc1 printf(quot;%+8.0d quot;, 2014); printf(quot; quot;); yc2 printf(quot;%+10.4f quot;, 3.14159); printf(quot; quot;); yc3 printf(quot;%4s %20s %11s %9s %10s quot;, quot;Sttquot;, quot;Ho va Tenquot;, quot;Diem toanquot;, quot;Diem lyquot;, quot;Diem hoaquot;); printf(quot;%s quot;, quot;quot;); printf(quot;%4d %23s %10.1f %9.1f %.1f quot;, 1, quot;Nguyen Lan Huongquot;, 7.0, 8.0, 10.0); printf(quot;%4d %22s %10.1f %10.1f %.1f quot;, 2, quot;Tran Thanh Binhquot;, 10.0, 10.0, 10.0); printf(quot;%4d %23sprintf(quot;Hello HCMUT 1411875 quot;); phan 1 printf(quot;%d quot;, 2014); printf(quot;%e %f %E quot;, 3.14159, 0.00057326, 3.14159); printf(quot;%c quot;, 39;A39;); printf(quot;%s quot;, quot;Dai hoc Bach Khoaquot;); printf(quot; DAI HOC BACH KHOA quot;); printf(quot; quot;); yc1 printf(quot;%+8.0d quot;, 2014); printf(quot; quot;); yc2 printf(quot;%+10.4f quot;, 3.14159); printf(quot; quot;); yc3 printf(quot;%4s %20s %11s %9s %10s quot;, quot;Sttquot;, quot;Ho va Tenquot;, quot;Diem toanquot;, quot;Diem lyquot;, quot;Diem hoaquot;); printf(quot;%s quot;, quot;quot;); printf(quot;%4d %23s %10.1f %9.1f %.1f quot;, 1, quot;Nguyen Lan Huongquot;, 7.0, 8.0, 10.0); printf(quot;%4d %22s %10.1f %10.1f %.1f quot;, 2, quot;Tran Thanh Binhquot;, 10.0, 10.0, 10.0); printf(quot;%4d %23sprintf(quot;Hello HCMUT 1411875 quot;); phan 1 printf(quot;%d quot;, 2014); printf(quot;%e %f %E quot;, 3.14159, 0.00057326, 3.14159); printf(quot;%c quot;, 39;A39;); printf(quot;%s quot;, quot;Dai hoc Bach Khoaquot;); printf(quot; DAI HOC BACH KHOA quot;); printf(quot; quot;); yc1 printf(quot;%+8.0d quot;, 2014); printf(quot; quot;); yc2 printf(quot;%+10.4f quot;, 3.14159); printf(quot; quot;); yc3 printf(quot;%4s %20s %11s %9s %10s quot;, quot;Sttquot;, quot;Ho va Tenquot;, quot;Diem toanquot;, quot;Diem lyquot;, quot;Diem hoaquot;); printf(quot;%s quot;, quot;quot;); printf(quot;%4d %23s %10.1f %9.1f %.1f quot;, 1, quot;Nguyen Lan Huongquot;, 7.0, 8.0, 10.0); printf(quot;%4d %22s %10.1f %10.1f %.1f quot;, 2, quot;Tran Thanh Binhquot;, 10.0, 10.0, 10.0); printf(quot;%4d %23sprintf(quot;Hello HCMUT 1411875 quot;); phan 1 printf(quot;%d quot;, 2014); printf(quot;%e %f %E quot;, 3.14159, 0.00057326, 3.14159); printf(quot;%c quot;, 39;A39;); printf(quot;%s quot;, quot;Dai hoc Bach Khoaquot;); printf(quot; DAI HOC BACH KHOA quot;); printf(quot; quot;); yc1 printf(quot;%+8.0d quot;, 2014); printf(quot; quot;); yc2 printf(quot;%+10.4f quot;, 3.14159); printf(quot; quot;); yc3 printf(quot;%4s %20s %11s %9s %10s quot;, quot;Sttquot;, quot;Ho va Tenquot;, quot;Diem toanquot;, quot;Diem lyquot;, quot;Diem hoaquot;); printf(quot;%s quot;, quot;quot;); printf(quot;%4d %23s %10.1f %9.1f %.1f quot;, 1, quot;Nguyen Lan Huongquot;, 7.0, 8.0, 10.0); printf(quot;%4d %22s %10.1f %10.1f %.1f quot;, 2, quot;Tran Thanh Binhquot;, 10.0, 10.0, 10.0); printf(quot;%4d %23s
Bài : #include "stdafx.h" #include void main() { printf("Hello HCMUT 1411875! \n"); //phan printf("%d\n", 2014); printf("%e\t%f\n%E\n", 3.14159, 0.00057326, 3.14159); printf("%c\n", 'A'); printf("%s\n", "Dai hoc Bach Khoa"); printf("\tDAI HOC BACH KHOA\n"); printf(" \n\n"); //yc1 printf("%-+8.0d\n", 2014); printf(" \n\n"); //yc2 printf("%-+10.4f\n", 3.14159); printf(" \n\n"); //yc3 printf("%-4s %-20s %-11s %-9s %-10s\n", "Stt", "Ho va Ten", "Diem toan", "Diem ly", "Diem hoa"); printf("%-s\n", " "); printf("%-4d %-23s %-10.1f %-9.1f %-.1f\n", 1, "Nguyen Lan Huong", 7.0, 8.0, 10.0); printf("%-4d %-22s %-10.1f %-10.1f %-.1f\n", 2, "Tran Thanh Binh", 10.0, 10.0, 10.0); printf("%-4d %-23s %-9.1f %-11.1f %-.1f\n", 3, "Vu Ngoc Thanh", 9.0, 10.0, 9.0); _getch(); } Bài 2: // Th2.cpp : du lieu hang va bien #include "stdafx.h" #include const float pi = 3.14159; void main() { int chon, tieptuc=1; while (tieptuc == 1) //kt dieu kien tiep tuc { printf("%s\n", "Ban muon lam gi?"); printf("\t%s\n", "1-tinh chu vi va dien tich hinh tron"); printf("\t%s\n", "2-tinh chu vi va dien tich hinh chu nhat"); printf("\t%s\n", "3-Tinh giao diem duong thang"); printf("\t%s\n", "4-Thoat khoi chuong trinh"); printf("%s", "Vui long nhap lua chon : "); scanf_s("%i", &chon); while ((chon != 1) && (chon != 2) && (chon != 3)&&(chon != 4)) //kt dieu kien chon lua { printf("%s\n", "Lua chon cua ban khong co he thong!!"); printf("%s\n", " "); printf("%s\n", "Ban muon lam gi?"); printf("\t%s\n", "1-tinh chu vi va dien tich hinh tron"); printf("\t%s\n", "2-tinh chu vi va dien tich hinh chu nhat"); printf("\t%s\n", "3-Thoat khoi chuong trinh"); printf("%s", "Vui long nhap lai lua chon : "); scanf_s("%i", &chon); } //end chon lua khong dung switch (chon) { case 1: //cv,dt hinh tron float r, cvdt, dtdt; printf("%s\n", " "); printf("%s", "Nhap ban kinh R= "); scanf_s("%f", &r); while (r < 0) //kt dieu kien ban kinh { printf("%s\n", "Ban kinh duong tron phai la so duong"); printf("%s\n", " "); printf("%s", "Vui long nhap lai ban kinh : "); scanf_s("%f", &r); } printf("%s%13.3f\n", "Ban kinh hinh tron da nhap la: ", r); cvdt = * pi*r; dtdt = pi*r*r; printf("%s%15.3f\n", "Chu vi hinh tron da nhap la: ", cvdt); printf("%s%12.3f\n", "Dien tich hinh tron da nhap la: ", dtdt); printf("%s", "Ban muon tiep tuc khong?(y/n) : "); scanf_s("%i", &tieptuc); printf("%s\n", " "); break; case 2: case 3: //cv,dt hcn float cr, cd, cvhcn, dthcn; printf("%s\n", " "); printf("%s", "Nhap chieu rong hinh chu nhat= "); scanf_s("%f", &cr); while (cr < 0) //kt dieu kien chieu rong hcn { printf("%s\n", "Chieu rong hcn phai la so duong"); printf("%s\n", " "); printf("%s", "Vui long nhap lai chieu rong hcn : "); scanf_s("%f", &cr); } printf("%s", "Nhap chieu dai hinh chu nhat = "); scanf_s("%f", &cd); while (cd < 0) //kt dieu kien chieu rong hcn { printf("%s\n", "Chieu dai hcn phai la so duong"); printf("%s\n", " "); printf("%s", "Vui long nhap lai chieu dai hcn : "); scanf_s("%f", &cd); } printf("%s\n", " -+ "); printf("%s%11.3f\n", "Chieu rong hinh chu nhat da nhap la: ", cr); printf("%s%15.3f\n", "Chieu dai hinh chu nhat nhap la: ", cd); cvhcn = * (cr + cd); dthcn = cr*cd; printf("%s%15.3f\n", "Chu vi hinh chu nhat da nhap la: ", cvhcn); printf("%s%12.3f\n", "Dien tich hinh chu nhat da nhap la: ", dthcn); printf("%s", "Ban muon tiep tuc khong?(1=y ; 0=n) : "); scanf_s("%i", &tieptuc); printf("%s\n", " "); break; //giao diem duong thang song song float a, a1, b, b1, x, y; printf("%s\n", " "); printf("%s", "Nhap he so a cua duong thang thu nhat= "); scanf_s("%f", &a); printf("%s", "Nhap he so b cua duong thang thu nhat= "); scanf_s("%f", &b); printf("%s", "Nhap he so a' cua duong thang thu nhat= "); scanf_s("%f", &a1); printf("%s", "Nhap he so b' cua duong thang thu nhat= "); scanf_s("%f", &b1); printf("%s\n", " -+ "); printf("%s%11.3f\n", " He so a cua duong thang thu nhat da nhap la: ", a); printf("%s%11.3f\n", " He so b cua duong thang thu nhat da nhap la: ", b); printf("%s%11.3f\n", " He so a' cua duong thang thu hai da nhap la: ", a1); printf("%s%11.3f\n", " He so b' cua duong thang thu hai da nhap la: ", b1); if ((a - a1) == 0) { printf("%s\n", "Hai duong thang da nhap song song, khong co giao diem!"); printf("%s\n", " "); } else { x = (b - b1) / (a - a1); y = a*x + b; printf("%s\n", "Giao diem cua duong thang da nhap co toa :"); printf("%s%11.3f\n", "x=", x); printf("%s%11.3f\n", "y=", y); } printf("%s", "Ban muon tiep tuc khong?(1=y ; 0=n) : "); scanf_s("%i", &tieptuc); printf("%s\n", " "); break; case 4: } printf("%s\n", " "); printf("%s\n", "See u again^^"); chon = 4; tieptuc =0; break; } } // end dieu kien tiep tuc printf("%s\n", " "); printf("%s\n", "See u again^^"); _getch(); Bài : // th3.cpp : su dung bien cau truc #include "stdafx.h" #include "conio.h" #include "Th3.h" void main() { int chon; printf("Nhap so bai : 3.1-3.2-3.3"); scanf_s("%d", &chon); switch chon case '1': { hoso sv1; printf("Nhap ho ten: "); scanf_s("%[a-z A-Z]", sv1.hoten); printf("Nhap MSSV: "); scanf_s("%s", sv1.ms); printf("\n"); printf("Nhap diem toan: "); scanf_s("%f", &sv1.diem_t); printf("Nhap diem ly: "); scanf_s("%f", &sv1.diem_l); printf("Nhap diem hoa: "); scanf_s("%f", &sv1.diem_h); sv1.diem_tong = sv1.diem_t + sv1.diem_l + sv1.diem_h; printf("%-20s %-8s %-10s %-10s %-10s %-10s\n", "Ho Ten", "MSSV", "Diem toan", "Diem ly", "Diem hoa", "Diem tong"); printf("%-s\n", " -"); printf("%-20s %-8s %-10.1f %-10.1f %-10.1f %-10.1f\n", sv1.hoten, sv1.ms, sv1.diem_t, sv1.diem_l, sv1.diem_h, sv1.diem_tong); } case '2': { hoso sv1, sv2, sv3, sv4, sv5; float diemthap[5]; printf("Nhap ho ten sv1 : "); scanf_s("%[a-z A-Z]", sv1.hoten); printf("Nhap MSSV: "); scanf_s("%s", sv1.ms); printf("\n"); printf("Nhap diem toan: "); scanf_s("%f", &sv1.diem_t); printf("Nhap diem ly: "); scanf_s("%f", &sv1.diem_l); printf("Nhap diem hoa: "); scanf_s("%f", &sv1.diem_h); sv1.diem_tong = sv1.diem_t + sv1.diem_l + sv1.diem_h; sv1.diem_tb = sv1.diem_tong / 3; if (sv1.diem_tb < 5) diemthap[1] = sv1.diem_tb; // printf("Nhap ho ten sv2 : "); scanf_s("%[a-z A-Z]", sv2.hoten); printf("Nhap MSSV: "); scanf_s("%s", sv2.ms); printf("\n"); printf("Nhap diem toan: "); scanf_s("%f", &sv2.diem_t); printf("Nhap diem ly: "); scanf_s("%f", &sv2.diem_l); printf("Nhap diem hoa: "); scanf_s("%f", &sv2.diem_h); sv2.diem_tong = sv2.diem_t + sv2.diem_l + sv2.diem_h; sv2.diem_tb = sv2.diem_tong / 3; if (sv2.diem_tb < 5) diemthap[1] = sv2.diem_tb; // printf("Nhap ho ten sv3 : "); scanf_s("%[a-z A-Z]", sv3.hoten); printf("Nhap MSSV: "); scanf_s("%s", sv3.ms); printf("\n"); printf("Nhap diem toan: "); scanf_s("%f", &sv3.diem_t); printf("Nhap diem ly: "); scanf_s("%f", &sv3.diem_l); printf("Nhap diem hoa: "); scanf_s("%f", &sv3.diem_h); sv3.diem_tong = sv3.diem_t + sv3.diem_l + sv3.diem_h; sv3.diem_tb = sv3.diem_tong / 3; if (sv3.diem_tb < 5) diemthap[1] = sv3.diem_tb; // printf("Nhap ho ten sv4 : "); scanf_s("%[a-z A-Z]", sv4.hoten); printf("Nhap MSSV: "); scanf_s("%s", sv4.ms); printf("\n"); printf("Nhap diem toan: "); scanf_s("%f", &sv4.diem_t); printf("Nhap diem ly: "); scanf_s("%f", &sv4.diem_l); printf("Nhap diem hoa: "); scanf_s("%f", &sv4.diem_h); sv4.diem_tong = sv4.diem_t + sv4.diem_l + sv4.diem_h; sv4.diem_tb = sv4.diem_tong / 3; if (sv4.diem_tb < 5) diemthap[1] = sv4.diem_tb; // printf("Nhap ho ten sv5 : "); scanf_s("%[a-z A-Z]", sv5.hoten); printf("Nhap MSSV: "); scanf_s("%s", sv5.ms); printf("\n"); printf("Nhap diem toan: "); scanf_s("%f", &sv5.diem_t); printf("Nhap diem ly: "); scanf_s("%f", &sv5.diem_l); printf("Nhap diem hoa: "); scanf_s("%f", &sv5.diem_h); sv5.diem_tong = sv5.diem_t + sv5.diem_l + sv5.diem_h; sv5.diem_tb = sv5.diem_tong / 3; if (sv5.diem_tb < 5) diemthap[1] = sv5.diem_tb; // printf("%-20s %-8s %-10s %-10s %-10s %-10s\n", "Ho Ten", "MSSV", "Diem toan", "Diem ly", "Diem hoa", "Diem tong","Diem TB"); printf("%-s\n", " -"); printf("%-20s %-8s %-10.1f %-10.1f %-10.1f %-10.1f %-10.1f\n", sv1.hoten, sv1.ms, sv1.diem_t, sv1.diem_l, sv1.diem_h, sv1.diem_tong,sv1.diem_tb); printf("%-20s %-8s %-10.1f %-10.1f %-10.1f %-10.1f %-10.1f\n", sv2.hoten, sv2.ms, sv2.diem_t, sv2.diem_l, sv2.diem_h, sv2.diem_tong, sv2.diem_tb); printf("%-20s %-8s %-10.1f %-10.1f %-10.1f %-10.1f %-10.1f\n", sv3.hoten, sv3.ms, sv3.diem_t, sv3.diem_l, sv3.diem_h, sv3.diem_tong, sv3.diem_tb); printf("%-20s %-8s %-10.1f %-10.1f %-10.1f %-10.1f %-10.1f\n", sv4.hoten, sv4.ms, sv4.diem_t, sv4.diem_l, sv4.diem_h, sv4.diem_tong, sv4.diem_tb); printf("%-20s %-8s %-10.1f %-10.1f %-10.1f %-10.1f %-10.1f\n", sv5.hoten, sv5.ms, sv5.diem_t, sv5.diem_l, sv5.diem_h, sv5.diem_tong, sv5.diem_tb); for (i=) } _getch(); } TH3.h typedef struct { char hoten[40]; char ms[8]; float diem_t; float diem_l; float diem_h; float diem_tong; float diem_tb; } hoso; Bài : // Th4.cpp :su dung if-else #include "stdafx.h" #include extern void tachso(); extern void sorachu(char ); int so; char kytu_n, kytu_t, kytu_c, kytu_dv; void main() { printf("Nhap so nguyen can tach: "); scanf_s("%d",&so); tachso(); if (kytu_n != '0') printf("%c-%c-%c %c" ,kytu_n, kytu_t, kytu_c, kytu_dv); else if (kytu_t != '0') printf("%c-%c-%c ", kytu_t, kytu_c, kytu_dv); else printf("%c-%c", kytu_c, kytu_dv); printf("\n"); //in so chu if (kytu_n != '0') { sorachu(kytu_n); sorachu(kytu_t); sorachu(kytu_c); sorachu(kytu_dv); } else if (kytu_t != '0') { sorachu(kytu_t); sorachu(kytu_c); sorachu(kytu_dv); } else { sorachu(kytu_c); sorachu(kytu_dv); } // -_getch(); } Tachso.cpp #include "stdafx.h" extern int so; extern char kytu_n, kytu_t, kytu_c,kytu_dv; void tachso() { kytu_n = (so / 1000) + '0'; kytu_t = (so / 100)%10 + '0'; kytu_c = (so / 10)%10 + '0'; kytu_dv = so%10 + '0'; } void sorachu(char kyso) { switch (kyso) { case '0':printf("khong "); break; case '1':printf("mot "); break; case '2':printf("hai "); break; case '3':printf("ba "); break; case '4':printf("bon "); break; case '5':printf("nam "); break; case '6':printf("sau "); break; } case '7':printf("bay "); break; case '8':printf("tam "); break; case '9':printf("chin "); break; } Bài : // Th5.cpp : dung vong lap while #include "stdafx.h" #include void main() { int chon, tieptuc = 1; int n, i, P, Pmax, S, nmax,n1,sochuso; while (tieptuc == 1) //kt dieu kien tiep tuc { printf("%s\n", "Menu chuc nang:"); printf("\t%s\n", "1-Tinh tong "); printf("\t%s\n", "2-Tinh tong so le"); printf("\t%s\n", "3-Tinh giai thua"); printf("\t%s\n", "4-Tinh tong cac so chia het cho 7"); printf("\t%s\n", "5-Tinh tong cac chu so cua mot so nguyen n"); printf("\t%s\n", "6-Thoat khoi chuong trinh"); printf("%s", "Vui long nhap lua chon : "); scanf_s("%i", &chon); while ((chon != 1) && (chon != 2) && (chon != 3) && (chon != 4) && (chon != 5) && (chon != 6))//kt dieu kien chon lua { printf("%s\n", "Lua chon cua ban khong co he thong!!"); printf("%s\n", " "); printf("%s\n", "Menu chuc nang:"); printf("\t%s\n", "1-Tinh tong "); printf("\t%s\n", "2-Tinh tong so le"); printf("\t%s\n", "3-Tinh giai thua"); printf("\t%s\n", "4-Tinh tong cac so chia het cho 7"); printf("\t%s\n", "5-Tinh tong cac chu so cua mot so nguyen n"); printf("\t%s\n", "6-Thoat khoi chuong trinh"); printf("%s", "Vui long nhap lai lua chon : "); scanf_s("%i", &chon); } //end chon lua khong dung switch (chon) { case 1: //tinh tong printf("%s\n", " "); printf("%s", "Nhap n= "); scanf_s("%d", &n); while (n < 0) //kt dieu kien n { printf("%s\n", "n phai la so duong"); printf("%s\n", " "); printf("%s", "Vui long nhap lai n : "); scanf_s("%d", &n); } printf("%s%-13d\n", "n da nhap la: ", n); i = 1; S = 0; while (i nmax) //kt dieu kien n { printf("%s%d\n", "n toi da la: ", nmax); printf("%s\n", " "); printf("%s", "Vui long nhap lai n : "); scanf_s("%d", &n); }*/ printf("%s%-13d\n", "n da nhap la: ", n); i = 1; P = 1; while (idiem_thi)); } float tinhdiem_tk(hoso *hs) { return hs->diem_tk = hs->diem_btl * 0.2 + hs->diem_kt * 0.2 + hs->diem_thi * 0.6; } void inhoso(hoso *hs) { printf("%s%s\n", "Ho va Ten: ", hs->hoten); printf("%s%s\n", "MSSV: ", hs->mssv); printf("%s%.1f\n", "Diem kiem tra: ", hs->diem_kt); printf("%s%.1f\n", "Diem blt: ", hs->diem_btl); printf("%s%.1f\n", "Diem thi: ", hs->diem_thi); printf("%s%.1f\n", "Diem tong ket: ", hs->diem_tk); printf("%s%.1f\n", "Diem tong ket lam tron: ",(int)((hs->diem_tk*4+1)/2)/2.); fprintf(stream, "%s%s%.2f%.2f%.2f%.2f%.2f\n", hs->hoten, hs->mssv, hs->diem_kt, hs->diem_btl, hs>diem_thi, hs->diem_tk, (((hs->diem_tk * + 1) / 2) / 2.)); } Ham.h extern void nhaphoso(hoso *); extern float tinhdiem_tk(hoso *); extern void inhoso(hoso *); Kieuhoso.h typedef struct { char hoten[40]; char mssv[9]; float diem_btl; float diem_kt; float diem_thi; float diem_tk; } hoso; extern FILE *stream; extern FILE *streamr; Bài 10: // th10.cpp : thao tac file #include "stdafx.h" #include #include "thapHN.h" int sobuoc; int sodia; FILE *stream; FILE *streamr; void main() { char cot1, cot2, cot3; /*cot1 = 'a'; cot2 = 'b'; cot3 = 'c'; */ streamr = fopen("ThapHN_ts.txt", "r"); stream = fopen("ThapHN.txt", "wt"); if (stream != NULL) { if (streamr != NULL) { puts("Cac buoc chuyen:"); fputs("Cac buoc chuyen:\n", stream); sobuoc = 0; sodia = 0; fscanf(streamr, "%d%c%c%c", &sodia,&cot1,&cot2,&cot3); chuyencot(sodia,cot1,cot2,cot3); fclose(streamr); fclose(stream); fclose(streamr); _getch(); } else puts("Khong the doc file!"); } else puts("Khong the tao file!"); _getch(); } ThapHn.cpp #include "stdafx.h" #include "Th10.h" void chuyendia(char cotdi, char cotden) { sobuoc++; printf("%s%d%s%c%s%c\n", "Buoc ", sobuoc, "\t:", cotdi, " >", cotden); fprintf(stream, "%s%d%s%c%s%c\n", "Buoc ", sobuoc, "\t:", cotdi, " >", cotden); } void chuyencot(int sodia, char cotdi, char cotden, char cottgi) { if (sodia > 0) { chuyencot(sodia - 1, cotdi, cottgi, cotden); chuyendia(cotdi, cotden); chuyencot(sodia - 1, cottgi, cotden, cotdi); } } ThapHN.h extern void chuyencot(int, char, char, char); extern void chuyendia( char, char); Th10.h extern extern extern extern int sobuoc; int sodia; FILE *stream; FILE *streamr;