code c all.doc

174
1. Download TC with dosbox 2. share code stack (ngăn xếp) lập trình c 3. share code queue (hàng đợi) lập trình c 4. share code danh sách hai chiều ( lập trình c) 5. code đọc mã phím (lập trình c) 6. code tìm các tập con của một tập hợp (lập trình c) 7. code đệ quy tìm UCLN, BCNN (lập trình c) 8. share code lưu 1 danh sách cấu trúc vào tệp tin 9. code tìm số có phần thập phân lớn nhất trong mảng 10. code bài toán vecto trong c 11. code nối 2 mảng một chiều thành một mảng một chiều 12. code bài toán về ma trận (lập trình c) 13. ví dụ code về mảng và con trỏ 14. code mảng 2 chiều trong c (lập trình c) 15. code mảng một chiều trong c 16. code ví dụ hàm main có đối dòng lệnh trong c 17. code chuẩn hóa xâu trong c 18. tự xây dựng hàm sử lý xâu ký tự (lập trình c) 19. code tính biểu thức toán học logic (lập trình c ) 20. code in bảng cửu chương (;ập trình c) 21. share code tính căn bậc 3 của một số 22. code các phép toán với đa thức 23. code tích vô hước của 2 vecto 24. code áp dụng taylor tính căn bậc 2 25. code giải bất phương trình bậc 2 một ẩn (lập trình c) 26. code giải phương trình bậc 3 (lập trình c) 27. code giải bất phương trình bậc 3 (lập trình c) 28. Code mẫu c++ căn bản cho anh em 29. Tìm giá trị lớn nhất của hai số,sử dụng hàm này để tìm mảng lớn nhất!! 30. code tìm số nguyên tố trong c++ 31. 4 thuật toán sắp xếp trong C 32. Bài tập đếm số lần xuất hiện các ký tự trong chuỗi 33. Bài tập in bảng cửu chương! 34. Bài tập về mảng trong C++ 35. [share code] giải thuật hòa nhập mergesort (lập trình c) 36. Code con trỏ tổng hợp 37. Code đệ quy tổng hợp 38. Code tổng hợp các bài mảng 1 chiều 39. bài tập trong turbo c 40. thao tác cơ bản trên mảng một chiều 41. kiểm tra nguyên tố và tính tổng giai thừa 42. Mời nhập vào 1 số có 3 chữ số và đánh vần số đó 43. Mời nhập vào 1 số có 2 chữ số và đánh vần số đó 44. mảng 2 chiều trong turbo c 45. Share mảng 1 chiều trong turbo c nhưng không sử dụng hàm 46. Share mảng 1 chiều trong turbo c có sử dụng hàm

Upload: vo-van-phuc

Post on 30-Sep-2015

238 views

Category:

Documents


1 download

TRANSCRIPT

1

1. Download TC with dosbox2. share code stack (ngn xp) lp trnh c3. share code queue (hng i) lp trnh c4. share code danh sch hai chiu ( lp trnh c)5. code c m phm (lp trnh c)6. code tm cc tp con ca mt tp hp (lp trnh c)7. code quy tm UCLN, BCNN (lp trnh c)8. share code lu 1 danh sch cu trc vo tp tin9. code tm s c phn thp phn ln nht trong mng10. code bi ton vecto trong c11. code ni 2 mng mt chiu thnh mt mng mt chiu12. code bi ton v ma trn (lp trnh c)13. v d code v mng v con tr14. code mng 2 chiu trong c (lp trnh c)15. code mng mt chiu trong c16. code v d hm main c i dng lnh trong c17. code chun ha xu trong c18. t xy dng hm s l xu k t (lp trnh c)19. code tnh biu thc ton hc logic (lp trnh c )20. code in bng cu chng (;p trnh c)21. share code tnh cn bc 3 ca mt s22. code cc php ton vi a thc23. code tch v hc ca 2 vecto24. code p dng taylor tnh cn bc 225. code gii bt phng trnh bc 2 mt n (lp trnh c)26. code gii phng trnh bc 3 (lp trnh c)27. code gii bt phng trnh bc 3 (lp trnh c)28. Code mu c++ cn bn cho anh em29. Tm gi tr ln nht ca hai s,s dng hm ny tm mng ln nht!!30. code tm s nguyn t trong c++31. 4 thut ton sp xp trong C32. Bi tp m s ln xut hin cc k t trong chui33. Bi tp in bng cu chng!34. Bi tp v mng trong C++35. [share code] gii thut ha nhp mergesort (lp trnh c)36. Code con tr tng hp37. Code quy tng hp38. Code tng hp cc bi mng 1 chiu39. bi tp trong turbo c40. thao tc c bn trn mng mt chiu41. kim tra nguyn t v tnh tng giai tha42. Mi nhp vo 1 s c 3 ch s v nh vn s 43. Mi nhp vo 1 s c 2 ch s v nh vn s 44. mng 2 chiu trong turbo c45. Sharemng 1 chiu trong turbo c nhng khng s dng hm46. Sharemng 1 chiu trong turbo c c s dng hm47. Sharemng 2 chiu khng s dng hm48. ShareSp xp danh sch Sinh Vin theo H Tn (Kiu Alpha).49. Hng dnly kch thc 1 file trong c50. KFMouse 1.3 - Do ti lm51. [Hi] Thut ton v code duyt th trong C52. Lp trnh Virus | Cch to Key khi ng cho Virus | vietsource.net53. Sharechia s code calculator54. ShareTr chi D mn lm t C55. Sharecode calculator 2.056. ShareCode Tr chi D mn phin bn 2.0 lm t C57. Sharecode tr chi bn tri tim (m phng bn bng)58. hm xa gi tr trng nhau trong mt mng59. ShareShare code+data bn hng cc chun60. Sharehm chuyn s nguyn sang xu61. code giai phng trinh bc 2 mt n62. Sharecode tinh giai tha bng d quy trong C63. Bi ton thp h ni - tower of hanoi64. Nhp, thm, sa, xa d liu trn DataGridView c bn nht65. Bi ton n mn hon ton mi. Xin gip v thut ton!66. Share[ an] ma hoa thng tin nhi phn67. Share n thut tim khoa, phu ti thiu, bao ong68. Tm 1 v tr m gi tr ti l gi tr nh nht trong mng 1 chiu cc s thc69. ShareBFS (Breadth First Search) - thut ton tm kim theo chiu rng trn th70. ShareBi ton Ci ti vit bng phng php Quy Hoch ng71. Mt s v d v ngn xp- hng i- danh sch lin kt.72. ShareM ngun phn mm crack md573. Sharecode tim tp con cua mt tp cho trc74. Shareng dng hng i - queue75. ShareChng trnh m phng thut ton Dijktra76. ShareCode cc hm c bn trong danh sch mng77. ShareCode cc hm (php ton) c bng trong danh sch lin kt n78. ShareCode mt s hm c bn trong danh sch sinh vn79. ShareCode nhp v cc php ton trn a thc dng danh sch lin kt80. ShareMt s php ton ci t trong hng i Queue dng mng81. ShareCode Dng Stack trong bi ton i c s82. ShareCode danh sch sinh vin s dng mng83. ShareMt s php ton ci t trong hng i Queue dng con tr (DSLK)84. Share[code] chng trinh quan ly nhn vin85. Tho luncode bai toan t du86. n qun l n tt nghip87. Sharecode tim day tng ln nht trong mt day cho trc88. ShareCode bi ton dy con tng di nht89. ShareCode Chui i xng90. Tho lunCode bo ton tm s nguyn t trong khong [a,b]91. bi ton ma phng92. ShareQBMAX ng i c tng ln nht93. Tho lunTm dy con di nht94. Tho lunthut dijsktra - tm ng i ngn nht trn th95. Cn thu ngi vit tool x l packet96. Tho lunbi ton Bc thang2.danh sch ngn xp stack

#include #include #include #include

// danh sach lien ket ngan xep. stack

struct sv{char ht[30];float diem;

sv *prev;};struct sv *p,*pcuoi;

void nhap(sv *p);void xuat(sv *p);void xoa(sv *p);void them(sv *p);

void nhap(sv *p){ char ten[30]; float d;

p=NULL;pcuoi=NULL;while(1){printf("nhap ten ");

fflush(stdin); //xoa bo nho dem ban phimgets(ten);fflush(stdin);

if (ten[0]=='\0') break;

p=(sv *)malloc(sizeof(sv));

strcpy((*p).ht,ten);printf("nhap diem "); scanf("%f",&d);(*p).diem=d;p->prev=pcuoi;pcuoi=p;

}

}

void xuat(sv *p){p=pcuoi;while (p!=NULL){printf("\t %s \t %6.2f \n",(*p).ht,(*p).diem);p=p->prev;}

}

void them(sv *p){sv *pt; char ten[30],kt[3]; float d;p=pcuoi;printf("chen vao cuoi danh sach y/n ?");fflush(stdin);gets(kt);fflush(stdin);if ( (strcmp(kt,"y")==0) || (strcmp(kt,"Y")==0) ){ printf("nhap ten "); gets(ten); fflush(stdin);if (ten[0]!='\0'){ pt=(sv *)malloc(sizeof(sv));strcpy((*pt).ht,ten);printf("nhap diem "); scanf("%f",&d);(*pt).diem=d;pt->prev=pcuoi;pcuoi=pt; free(pt);printf("\nchen thanh cong");}}if ( (strcmp(kt,"n")==0)||(strcmp(kt,"N")==0) ){printf("chen 1 nguoi truoc nguoi co ten la ");

gets(ten);fflush(stdin);while(p!=NULL){if (strcmp((*p).ht,ten)==0){printf("nhap ten ");gets(ten);fflush(stdin);if (ten[0]=='\0') break;else {

strcpy((*pt).ht,ten);printf("nhap diem "); scanf("%f",&d);(*pt).diem=d;pt->prev=p->prev;p->prev=pt;free(pt);printf("da chen thanh cong");break;}

}elsep=p->prev;if (p==NULL) printf("khong co nguoi nao ten la \"%s\" trong danh sach",ten);}}}

void xoa(sv *p){ char ten[30]; sv *pt;printf("ten nguoi muon xoa "); fflush(stdin); gets(ten); fflush(stdin);if (ten[0]!='\0'){p=pcuoi;while (p!=NULL){if (strcmp((*p).ht,ten)==0){if (strcmp((*pcuoi).ht,ten)==0){pcuoi=pcuoi->prev;free(p);

}else{pt->prev=p->prev;free(p);}

printf("da xoa \"%s\" khoi danh sach",ten);break;

}pt=p;

p=p->prev;if (p==NULL) printf("nguoi ban muon xoa khong co ten trong danh sach");}}

}

void main(){ int cv;

while(1)

{clrscr();printf("danh sach lien ket ngan xep (stack) ");printf("\n chon cong viec ");printf("\n1: nhap danh sach ");printf("\n2: hien danh sach ");printf("\n3: them 1 nguoi vao danh sach");printf("\n4: xoa 1 nkhoi danh sach");printf("\n5: thoat ");fflush(stdin);scanf("%d",&cv);

switch (cv)

{ case 1:{ clrscr(); nhap(p); break; }case 2:{ clrscr(); xuat(p); break; }case 3:{ clrscr(); them(p); break; }case 4:{ clrscr(); xoa(p); break; }case 5:{ goto thoat; }

}getch();

}thoat:}

code queue (hng i)

#include #include #include #include #include // danh sach lien ket thuan- hang doi - queue

struct sv{char ht[30];float diem;

sv *next;

};struct sv *p,*pdau,*pcuoi;

void nhap(sv *p);void xuat(sv *p);void xoa(sv *p);void them(sv *p);sv *maxdiem(sv *p);void sapxepnoibot(sv *p);void hoanvi(sv *p, sv *q);void nhap(sv *p){ char ten[30]; float d;

pdau=NULL;

while(1){printf("nhap ten ");

fflush(stdin); //xoa bo nho dem ban phimgets(ten);

if (ten[0]=='\0') break;

if (pdau==NULL){pdau=(sv *)malloc(sizeof(sv));p=pdau;

}else{

p->next=(sv *)malloc(sizeof(sv));p=p->next;}strcpy((*p).ht,ten);printf("nhap diem "); scanf("%f",&d);(*p).diem=d;p->next=NULL;

}

p=pdau;while (p!=NULL){printf("\t %s \t %6.2f \n",(*p).ht,(*p).diem);p=p->next;}

}

void xuat(sv *p){p=pdau;while (p!=NULL){printf("\t %s \t %6.2f \n",(*p).ht,(*p).diem);p=p->next;}

}

void them(sv *p){sv *pt; char ten[30],kt[3]; float d;p=pdau;printf("chen vao dau danh sach y/n ?");fflush(stdin);gets(kt);fflush(stdin);if ( (strcmp(kt,"y")==0) || (strcmp(kt,"Y")==0) ){ printf("nhap ten "); gets(ten); fflush(stdin);if (ten[0]!='\0'){ pt=(sv *)malloc(sizeof(sv));strcpy((*pt).ht,ten);printf("nhap diem "); scanf("%f",&d);(*pt).diem=d;pt->next=p;pdau=pt;printf("\nchen thanh cong");}}if ( (strcmp(kt,"n")==0)||(strcmp(kt,"N")==0) ){p=pdau;printf("chen 1 nguoi sau nguoi co ten la ");

gets(ten);fflush(stdin);while(p!=NULL){if (strcmp((*p).ht,ten)==0){printf("nhap ten ");gets(ten);fflush(stdin);if (ten[0]=='\0') break;else {strcpy((*pt).ht,ten);printf("nhap diem "); scanf("%f",&d);(*pt).diem=d;pt->next=p->next;p->next=pt;

printf("da chen thanh cong");break;}

}elsep=p->next;if (p==NULL) printf("khong co nguoi nao ten la \"%s\" trong danh sach",ten);}}}

void xoa(sv *p){ char ten[30]; sv *pt;printf("ten nguoi muon xoa "); fflush(stdin); gets(ten);if (ten[0]!='\0'){p=pdau;while (p!=NULL){if (strcmp((*p).ht,ten)==0){if (strcmp((*pdau).ht,ten)==0){pdau=p->next;free(p);}else{pt->next=p->next;free(p);}

printf("da xoa \"%s\" khoi danh sach",ten);free(ten);break;

}pt=p;

p=p->next;if (p==NULL) printf("nguoi ban muon xoa khong co ten trong danh sach");}}

}

sv *maxdiem(sv *p){ sv *svmax;for (svmax=pdau, p=pdau; p!=NULL ; p=p->next){if (p->diem>svmax->diem) svmax=p;}return svmax;}

void sapxepnoibot(sv *p){ sv *k; int kt;

printf("\n cho kieu sap xep ");printf("\n 1 : tang dan theo diem ");printf("\n 2 : giam dan theo diem ");printf("\n 3 : Theo ten A->Z ");printf("\n 4 : Theo ten Z->A \n");scanf("%d",&kt);switch(kt){case 1:{ for (k=pdau; k!=NULL; k=k->next){for (p=pdau; (p->next)!=NULL ;p=p->next ){if (((*p).diem)>((*(p->next)).diem)){hoanvi(p,p->next);}}} break;}case 2:{for (k=pdau; k!=NULL; k=k->next){for (p=pdau; (p->next)!=NULL ;p=p->next ){if (((*p).diem)next)).diem)){hoanvi(p,p->next);}}} break;}case 3:{for (k=pdau; k!=NULL; k=k->next){for (p=pdau; (p->next)!=NULL ;p=p->next ){if (strcmp((*p).ht,(*(p->next)).ht) >=0){hoanvi(p,p->next);}}}break;}

case 4:{for (k=pdau; k!=NULL; k=k->next){for (p=pdau; (p->next)!=NULL ;p=p->next ){if (strcmp((*p).ht,(*(p->next)).ht) next);}}}break;}

}

printf("\n sap xep thanh cong");}

void hoanvi(sv *p,sv *q){sv temp;temp=*p; // temp luu info va address cua q.next*p=*q;*q=temp;q->next=p->next; // cho dia chi cua q.next = dia chi cua con tro sau nop->next=temp.next; // gan dia chi &p.next = &q ;

}

void main(){ int cv; sv *p1,*p2; char ten1[30],ten2[30];

while(1)

{// clrscr();printf(" danh sach lien ket hang doi (queue)");printf("\n chon cong viec ");printf("\n1: nhap danh sach ");printf("\n2: hien danh sach ");printf("\n3: them 1 nguoi vao danh sach");printf("\n4: xoa 1 nkhoi danh sach");printf("\n5: sinh vien co diem lon nhat");printf("\n6: sap xep tang dan diem (noi bot)");printf("\n7: hoan vi 2 sinh vien ");printf("\n8: thoat ");fflush(stdin);scanf("%d",&cv);

switch (cv)

{ case 1:{ system("cls"); nhap(p); break; }case 2:{ system("cls"); xuat(p); break; }case 3:{ system("cls"); them(p); break; }case 4:{ system("cls"); xoa(p); break; }case 5:{ system("cls"); sv *tam; tam=maxdiem(p);printf("ten : %s \n diem: %6.2f",tam->ht,tam->diem);break;}case 6:{ system("cls"); sapxepnoibot(p); break;}case 7:{ printf("ten nguoi thu nhat : ") ;fflush(stdin);gets(ten1);fflush(stdin);printf("ten nguoi thu hai : ");gets(ten2);for (p=pdau; p!=NULL; p=p->next)if(strcmp((*p).ht,ten1)==0){p1=p; continue;}

for (p=pdau; p!=NULL; p=p->next)if(strcmp((*p).ht,ten2)==0){p2=p; continue;}

hoanvi(p1,p2);break;}case 8:{exit(1); }}getch();

}}

//======================

danh sch 2 chiu

#include #include #include #include

// danh sach lien ket 2 chieu

struct sv{char ht[30];float diem;

sv *next;sv *prev;};struct sv *p,*pdau,*pcuoi;

void nhap(sv *p);void xuatstack(sv *p);void xuatqueue(sv *p);void xoa(sv *p);void them(sv *p);

void nhap(sv *p){ char ten[30]; float d;

pdau=NULL;pcuoi=NULL;while(1){printf("nhap ten ");

fflush(stdin); //xoa bo nho dem ban phimgets(ten);fflush(stdin);

if (ten[0]=='\0') break;

p=(sv *)malloc(sizeof(sv));

strcpy((*p).ht,ten);printf("nhap diem "); scanf("%f",&d);(*p).diem=d;if (pdau==NULL) pdau=pcuoi=p;else{p->prev=pcuoi; // cho phan tu sau co dia chi cua phan tu dau;pcuoi->next=p; // cho phan tu dau co dia chi cua phan tu sau no;pcuoi=p; // cho pcuoi tro toi phan tu cuoi cung.}}

}

void xuatstack(sv *p){p=pcuoi;while (p!=NULL){printf("\t %s \t %6.2f \n",(*p).ht,(*p).diem);p=p->prev;}

}

void xuatqueue(sv *p){for (p=pdau; p!=NULL ;p=p->next)printf("\t%s \t %6.2f \n",(*p).ht,(*p).diem);

}

void them(sv *p){sv *pt; char ten[30],kt[3]; float d;p=pcuoi;printf("chen vao cuoi danh sach (stack) y/n ?");fflush(stdin);gets(kt);fflush(stdin);if ( (strcmp(kt,"y")==0) || (strcmp(kt,"Y")==0) ){ printf("nhap ten "); gets(ten); fflush(stdin);if (ten[0]!='\0'){ pt=(sv *)malloc(sizeof(sv));strcpy((*pt).ht,ten);printf("nhap diem "); scanf("%f",&d);(*pt).diem=d;pt->prev=pcuoi;pcuoi->next=pt;pcuoi=pt; free(pt);printf("\nchen thanh cong");}}if ( (strcmp(kt,"n")==0)||(strcmp(kt,"N")==0) ){printf("chen 1 nguoi truoc nguoi co ten la ");

gets(ten);fflush(stdin);while(p!=NULL){if (strcmp((*p).ht,ten)==0){printf("nhap ten ");gets(ten);fflush(stdin);if (ten[0]=='\0') break;else {

strcpy((*pt).ht,ten);printf("nhap diem "); scanf("%f",&d);(*pt).diem=d;if ((p==pdau)&&(p->next==pdau->next)){pdau->prev=pt;pt->next=pdau;pdau=pt;

}else{pt->prev=p->prev;(p->prev)->next=pt;p->prev=pt;pt->next=p;}free(pt);printf("da chen thanh cong");break;}

}elsep=p->prev;if (p==NULL) printf("khong co nguoi nao ten la \"%s\" trong danh sach",ten);}}}

void xoa(sv *p){ char ten[30]; sv *pt;printf("ten nguoi muon xoa "); fflush(stdin); gets(ten); fflush(stdin);if (ten[0]!='\0'){p=pcuoi;while (p!=NULL){if (strcmp((*p).ht,ten)==0){if (strcmp((*pcuoi).ht,ten)==0){pcuoi=pcuoi->prev;free(p);

}else{pt->prev=p->prev;free(p);}

printf("da xoa \"%s\" khoi danh sach",ten);break;

}pt=p;

p=p->prev;if (p==NULL) printf("nguoi ban muon xoa khong co ten trong danh sach");}}

}

void main(){ int cv;

while(1)

{clrscr();printf("danh sach lien ket 2 chieu ");printf("\n chon cong viec ");printf("\n1: nhap danh sach ");printf("\n2: hien danh sach theo stack ");printf("\n3: hien danh sach theo queue ");printf("\n4: them 1 nguoi vao danh sach");printf("\n5: xoa 1 nkhoi danh sach");printf("\n6: thoat ");fflush(stdin);scanf("%d",&cv);

switch (cv)

{ case 1:{ clrscr(); nhap(p); break; }case 2:{ clrscr(); xuatstack(p); break; }case 3:{ clrscr(); xuatqueue(p); break; }case 4:{ clrscr(); them(p); break; }case 5:{ clrscr(); xoa(p); break; }case 6:{ goto thoat; }

}getch();

}thoat:}

//==================

code c m phm

#include // doc ma phim nhap vao#includevoid main(void){

char c;do{c=getch();printf("%d\n",c);}while(1);getch();}

code c xem phm va n l phm kp hay phm n

#include#includevoid main(){char c;do{c=getche();if (c==0){c=getche();printf(" - Phim kep: 0 + %d\n",c);}else printf(" - Phim don: %d\n",c);}while(1);getch();}

//=============

rnh ngi code chng trnh tm tp con ca mt tp hpv d ta c tp A={1,2,3}th cc tp con l : A1={1},A2={2},A3={3},A4={1,2},A5={1,3},A6={2,3}

#include #include #include #include void Next_SubSet(void);void GenerateSet(void);void Result(void);int *A, Stop, n ,k; char *th[255] ,*tg="abc";void Next_SubSet(){int i,j;i = k; // duyet toi cuoi day// lap khi chua tim duoc phan tu chua toi gioi hanwhile (i >0 && A[i] == n-k+i)i--; // duyet voi dauif ( i > 0){A[i] = A[i] +1; // tang mot don vi// cho cac phan tu c?n l?i qua gi?i h?n du?ifor(j = i+1; j