Admins Thái Thượng Hoàng
Tổng số bài gửi : 336 Age : 35 Đến từ : cát bụi Registration date : 03/04/2008
| Tiêu đề: CAC BAI GIAI MAI THI HOC THUOC LONG DE Wed Jun 11, 2008 7:57 pm | |
| - Code:
-
#include<conio.h> #include<stdio.h> #include<math.h> double GT24D(int n); //============================ void main() { int n; char ch; double s=1,gt=1; do { printf("\n\t CT Tinh GT S=1+3!+5!+....(2*n+i)!!"); printf("\n\t Moi Nhap Gia Tri N:"); scanf("%d",&n); s=GT24D(n); printf("\n\t Neu N=%d,Thi Ket Qua S=%14.0f",n,s); printf("\n\t Ban Co Muon Tie1p Tuc Hok (C/K)"); ch=getch(); } while((ch=='C')||(ch=='c')); getch(); } //================================= double GT24D(int n) { double s=1,gt=1; for(int i=1;i<=n;i++) { gt=gt*(2*i)*(2*i+1); s=s+gt; } return s; } - Code:
-
/* Chuong trinh xu ly mang 2 chieu - Nhap mang - Xuat mang - Them 1 PTu vao mang - Xoa 1 phan tu trong mang - tim kiem - Sap Xep - So Nguyen To */ #include<conio.h> #include<stdio.h> #include<math.h> #define rows 10 #define cols 10
//=========================================== //Khai Bao cac Prototype void NhapMang (int a[][cols], int n, int m); void XuatMang (int a[][cols], int n, int m); void NhapDS (int b[], int m); void Them1Dong(int a[][cols], int *n, int m, int vt, int b[cols]); void Them1Cot(int a[][cols], int n, int *m, int vt, int b[rows]); void Xoa1Dong(int a[][cols], int *n, int m, int vt); void Xoa1Cot(int a[][cols], int n, int *m, int vt); void TongDong (int a[][cols], int n, int m); void TongCot (int a[][cols], int n, int m); void SapXep (int a[][cols], int n, int m); void InSNTo (int a[][cols], int n, int m); void InCheoChinh (int a[][cols], int n, int m); void InCheoPhu (int a[][cols], int n, int m); int KTSNTo (int x);
void main() { int a[rows][cols], n, m, kt, x, vt; int b[cols]; char chon; clrscr(); do { clrscr(); printf("\n\tCHUONG TRINH XU LY MANG 2 CHIEU !"); printf("\n\tCAC CHUC NANG TRONG CHUONG TRINH !"); printf("\n\t1 : Nhap Mang Moi !"); printf("\n\t2 : Xuat Mang !"); printf("\n\t3 : Them 1 Dong Vao Mang !"); printf("\n\t4 : Xoa 1 Dong Trong Mang !"); printf("\n\t5 : Them 1 Cot Vao Mang !"); printf("\n\t6 : Xoa 1 Cot Trong Mang !"); printf("\n\t7 : In cac Phan tu La So Nguuyen To !"); printf("\n\t8 : Sap Xep Tung Dong Theo Thu Tu Tang !"); printf("\n\t9 : Tinh Tong Tung Dong !"); printf("\n\t10 : Tinh Tong Tung Cot !"); printf("\n\t11 : In cac Phah Tu Nam tren Duong Cheo Chinh !"); printf("\n\t12 : In Cac Phan Tu Nam Tren Duong Cheo Phu !"); printf("\n\t..... !"); printf("\n\t0 : Thoat Khoi Chuong Trinh !"); printf("\n\tban Chon Chuc Nang Nao ? "); scanf("%d", &chon); switch(chon) { case 1: { clrscr(); printf("\n\tNhap Mang Moi !"); printf("\n\tNhap So Dong & Cot : "); scanf("%d%d", &n, &m); printf("\n\tNhap Noi Dung Cac PTu !\n"); NhapMang (a, n, m); break;
} case 2: { printf("\n\tMang Nhap Vao La !\n\t"); XuatMang (a, n, m); getch(); break; } case 3: { //Them 1 Dong vao DS printf("\n\tThem 1 Dong Vao Mang A !"); printf("\n\tMang Truoc Khi Them !\n\t"); XuatMang (a, n, m); printf("\n\tNhap VTri Can Them (0 => %d) : ", n); scanf ("%d", &vt); if (vt < 0 || vt > n) printf("\n\tVi Tri Them Khong Hop Le !"); else { printf("\n\tNhap Day Can Them !\n"); NhapDS (b, m); Them1Dong (a, &n, m, vt, b); printf("\n\tMang Sau Khi Them !\n\t"); XuatMang (a, n, m); } getch(); break; } case 4: { //Xoa 1 Dong vao DS printf("\n\tXoa 1 Dong Trong Mang A !"); printf("\n\tMang Truoc Khi Xoa !\n\t"); XuatMang (a, n, m); printf("\n\tNhap VTri Can Xoa (0 => %d) : ", n - 1); scanf ("%d", &vt); if (vt < 0 || vt >= n) printf("\n\tVi Tri Xoa Khong Hop Le !"); else { Xoa1Dong (a, &n, m, vt); printf("\n\tMang Sau Khi Xoa !\n\t"); XuatMang (a, n, m); } getch(); break; } case 5: { //Them 1 Cot vao DS printf("\n\tThem 1 Cot Vao Mang A !"); printf("\n\tMang Truoc Khi Them !\n\t"); XuatMang (a, n, m); printf("\n\tNhap VTri Can Them (0 => %d) : ", m); scanf ("%d", &vt); if (vt < 0 || vt > m) printf("\n\tVi Tri Them Khong Hop Le !"); else { printf("\n\tNhap Day Can Them !\n"); NhapDS (b, n); Them1Cot (a, n, &m, vt, b); printf("\n\tMang Sau Khi Them !\n\t"); XuatMang (a, n, m); } getch(); break; } case 6: { //Xoa 1 Dong vao DS printf("\n\tXoa 1 Cot Trong Mang A !"); printf("\n\tMang Truoc Khi Xoa !\n\t"); XuatMang (a, n, m); printf("\n\tNhap VTri Can Xoa (0 => %d) : ", m - 1); scanf ("%d", &vt); if (vt < 0 || vt >= m) printf("\n\tVi Tri Xoa Khong Hop Le !"); else { Xoa1Cot (a, n, &m, vt); printf("\n\tMang Sau Khi Xoa !\n\t"); XuatMang (a, n, m); } getch(); break; } case 7: { //In Cac PTu Trong Mang La SNT printf("\n\tIn Cac PTu Trong Mang La SNT !"); printf("\n\tMang Hien Tai La !\n\t"); XuatMang (a, n, m); printf("\n\tCac Phan Tu La SNTo !\n\t"); InSNTo (a, n, m); getch(); break; } case 8: { //SapXep printf("\n\tSap Xep Tung Dong Mang Theo Thu Tu Tang Dan !\n\t"); printf("\n\tMang Truoc Khi Sap Xep !\n\t"); XuatMang (a, n, m); SapXep (a, n, m); printf("\n\tMang Sau Khi Sap Xep !\n\t"); XuatMang (a, n, m); getch(); break; } case 9: { //Tong Tung Dong printf("\n\tTinh Tong Tung dong Cua Mang !\n\t"); printf("\n\tMang Hien Tai La !\n\t"); XuatMang (a, n, m); printf("\n\tTong Tung Dong !\n\t"); TongDong (a, n, m); getch(); break; } case 10: { //Tong Tung Cot printf("\n\tTinh Tong Tung Cot Cua Mang !\n\t"); printf("\n\tMang Hien Tai La !\n\t"); XuatMang (a, n, m); printf("\n\tTong Tung Cot !\n\t"); TongCot (a, n, m); getch(); break; } case 11: { //In Cheo Chinh printf("\n\tIn Cac Phan Tu Nam Tren Dong Cheo Chinh !\n\t"); printf("\n\tMang Hien Tai La !\n\t"); XuatMang (a, n, m); printf("\n\tCac Phan Tu Nam Tren Duong Cheo Chinh !\n\t"); InCheoChinh (a, n, m); getch(); break; } case 12: { //In Cheo Phu printf("\n\tIn Cac Phan Tu Nam Tren Dong Cheo Phu !\n\t"); printf("\n\tMang Hien Tai La !\n\t"); XuatMang (a, n, m); printf("\n\tCac Phan Tu Nam Tren Duong Cheo Phu !\n\t"); InCheoPhu (a, n, m); getch(); break; } }//KT Switch }while (chon > 0); getch(); }
//============================================ //Cai Dat Cac Ham //================================== void NhapMang (int a[][cols], int n, int m) { int i, j, x; for (i = 0; i < n; i++) //Dong for (j = 0; j < m; j++) //Cot { printf("\n\tNhap PTu A[%d][%d] : ", i, j); scanf("%d", &x); a[i][j] = x; } } //============================== //Nhap Mang 1 Chieu De Them 1 Dong / 1 Cot Vao mang void NhapDS (int b[], int m) { int j ; for (j = 0; j < m; j++) //Cot { printf("\n\tNhap PTu B[%d] : ", j); scanf("%d", &b[j]); } }
//================================== //In Mang Hai Chieu void XuatMang (int a[][cols], int n, int m) { int i, j; for (i = 0; i < n; i++) { printf("\n\t"); //Xuong Dong for (j = 0; j < m; j++) printf("%7d", a[i][j]); //(2) } } //================================= //In Cac Phan Tu Nam Tren Duong Cheo Chinh void InCheoChinh (int a[][cols], int n, int m) { int i, spt; if (n > m) spt = m; else spt = n; for (i = 0; i < spt; i++) printf("%7d", a[i][i]); } //================================= //In cac Phan Tu Nam tren Duong Cheo Phu void InCheoPhu (int a[][cols], int n, int m) { int i, spt; if (n > m) spt = m; else spt = n; for (i = 0; i < spt; i++) printf("%7d", a[i][m - i - 1]); }
//================================== //sap xep tung Dong Theo thu Tu tang void SapXep (int a[][cols], int n, int m) { int i, j, tam, k; for (i = 0; i < n; i++) //dong for (j = 0; j < m-1; j++) //dot for (k = j + 1; k < m; k++) if (a[i][j] > a[i][k]) { tam = a[i][j]; a[i][j] = a[i][k]; a[i][k] = tam; } } //================================== //Kiem tra So X Co Phai La SNguyen to Khong int KTSNTo (int x) { int k, l; if (x >= 2) { k = (int) sqrt (x); l = 2; while ((l <= k) && (x % l != 0)) l++; if (l > k) return 1;//la SNT return 0;// Khopng La SNTo } return 0;// Khopng La SNTo }
//================================== //In Cac Phan Tu La So Nguyen to void InSNTo (int a[][cols], int n, int m) { int i, kt, j; for (i = 0; i < n; i++) for (j = 0; j < m; j++) { kt = KTSNTo (a[i][j]); if (kt == 1) //a[i] la SNT printf("%7d", a[i][j]); } } //======================================== //Them 1 Dong Vao Mang void Them1Dong(int a[][cols], int *n, int m, int vt, int b[]) { int i, j; if (*n == rows) printf("\n\tMang Day Khong Them Duoc !"); else if ((vt < 0) || (vt > *n)) printf("\n\tVi Tri Them Khong Hop Le !"); else { //Doi cac Dong Tu Cuoi Den VT Them Le 1 Dong for (i = *n; i > vt; i--) //Dong for (j = 0; j < m; j++) //Cot a[i][j] = a[i-1][j]; //KT Viec Doi //Dua Day Them Vao mang for (j = 0; j < m; j++) //Cot a[vt][j] = b[j]; *n = *n + 1; //Tang So Dong 1 DV } } //======================================== //Xoa 1 Dong Trong Mang void Xoa1Dong(int a[][cols], int *n, int m, int vt) { int i, j; if (*n == 0) printf("\n\tMang Rong Khong Xoa Duoc !"); else if ((vt < 0) || (vt >= *n)) printf("\n\tVi Tri Xoa Khong Hop Le !"); else { //Doi cac Dong Tu VT Xoa Den Cuoi Xuong 1 Dong for (i = vt + 1; i < *n; i++) //Dong for (j = 0; j < m; j++) //Cot a[i - 1][j] = a[i][j]; //KT Viec Doi *n = *n - 1; //Giam So Dong 1 DV } }
//======================================== //Them 1 Cot Vao Mang void Them1Cot(int a[][cols], int n, int *m, int vt, int b[rows]) { int i, j; if (*m == cols) printf("\n\tMang Day Khong Them Duoc !"); else if ((vt < 0) || (vt > *m)) printf("\n\tVi Tri Them Khong Hop Le !"); else { //Doi cac Cot Tu Cuoi Den VT Them Le 1 Cot for (j = *m; j > vt; j--) //Cot for (i = 0; i < n; i++) //Dong a[i][j] = a[i][j - 1]; //KT Viec Doi //Dua Day Them Vao mang for (i = 0; i < n; i++) //Dong a[i][vt] = b[i]; *m = *m + 1; //Tang So Cot 1 DV } } //======================================== //Xoa 1 Cot Trong Mang void Xoa1Cot(int a[][cols], int n, int *m, int vt) { int i, j; if (*m == 0) printf("\n\tMang Rong Khong Xoa Duoc !"); else if ((vt < 0) || (vt >= *m)) printf("\n\tVi Tri Xoa Khong Hop Le !"); else { //Doi cac Cot Tu VT Xoa Den Cuoi Xuong 1 Cot for (j = vt + 1; j < *m; j++) //Cot for (i = 0; i < n; i++) //Dong a[i][j-1] = a[i][j]; //KT Viec Doi *m = *m - 1; //Giam So Cot 1 DV } } //================================== //Tinh Tong Tung Dong void TongDong (int a[][cols], int n, int m) { float td; int i, j; for (i = 0; i < n; i++) { td = 0; for (j = 0; j < m; j++) td = td + a[i][j]; printf("\n\tTong Dong Thu %d La %7.1f", i, td); } } //=============================== //Tinh Tong Tung Cot void TongCot (int a[][cols], int n, int m) { float tc; int i, j; for (j = 0; j < m; j++) { tc = 0; for (i = 0; i < n; i++) tc = tc + a[i][j]; printf("\n\tTong Dong Thu %d La %7.1f", i, tc); } } //=============================== //.........................
- Code:
-
#include<conio.h> #include<stdio.h> #include<math.h> double LT24E(int n,int x); //============================ void main() { int n,x; char ch; double lt=x,s=x; do { printf("\n\t CT Tinh GT S=X+X^3+X^5+....+X^(2*n+i)"); printf("\n\t Moi Nhap Gia Tri X:"); scanf("%d",&x); printf("\n\t Moi Nhap Gia Tri N:"); scanf("%d",&n); lt=LT24E(n,x); printf("\n\t Neu X=%d,N=%d,Thi Ket Qua S=%14.0f",x,n,lt); printf("\n\t Ban Co Muon Tiep Tuc Hok (C/K)"); ch=getch(); } while((ch=='C')||(ch=='c')); getch(); } //================================= double LT24E(int n,int x) { double lt=x,s=x; for(int i=1;i<=n;i++) { lt=lt*x*x; s=s+lt; } return s; } | |
|