Đề 1: #include<stdio.h> #include <conio.h> #include <math.h> int main() { int N; do{ printf("Nhap N: "); scanf("%d",&N); }while(N<=0 || N>=10); int A[N], i; for(i=0;i<N;i++){ printf("Nhap so thu %d: ",i+1); scanf("%d",&A[i]); } printf("Mang da nhap vao: "); for(i=0;i<N;i++){ printf("%d ",A[i]); } int X; do{ printf("Nhap X: "); scanf("%d",&X); }while(X<=0); if(X<=N){ int sum = 0; for(i=0;i<X;i++){ sum += A[i]; } printf("Trung binh cong cua %d so dau tien la: %f",X,1.0*sum/X); }else{ int sum = 0; for(i=0;i<N;i++){ sum += A[i]; } printf("Tong cac so trong mang la: %d",sum); } getch(); } Đề 2 #include <stdio.h> #include <conio.h> #include <math.h> int main() { int A[7], i, n = 0; for(i=0;i<7;i++){ printf("Nhap so thu %d: ",i+1); scanf("%d",&A[i]); if(A[i]==0){ break; }else{ n++; } } printf("Mang da nhap vao: "); for(i=0;i<n;i++){ printf("%d ",A[i]); } while(1){ bool flag = true; for(i=0;i<n-1;i++){ if(A[i]>A[i+1]){ int tmp = A[i]; A[i] = A[i+1]; A[i+1] = tmp; flag = false; } } if(flag){ break; } } printf("\nMang da sap xep: "); for(i=0;i<n;i++){ printf("%d ",A[i]); } getch(); } Đề 3: #include<stdio.h> #include<conio.h> main() { float a[15],max; int n,i,t=0; do { printf("Nhap so nguyen 0<n<10: "); scanf("%d",&n); }while((n<1)||(n>9)); for(i=0;i<n;i++) { printf("a[%d]= ",i); scanf("%f",&a[i]); } printf("Mang vua nhap: "); max=a[0]; for(i=0;i<n;i++) { printf("%.2f ",a[i]); if(a[i]>max) max=a[i]; } printf("\nGia tri lon nhat cua day la: %.2f",max); for(i=0;i<n;i++) if(a[i]==max) t=t+1; printf("\nSo luong phan tu bang gia tri lon nhat la: %d",t); getch(); } Đề 4 #include<stdio.h> #include<conio.h> main() { float a[15],min; int n,i,t=0; do { printf("Nhap so nguyen 0<n<10: "); scanf("%d",&n); }while((n<1)||(n>9)); for(i=0;i<n;i++) { printf("a[%d]= ",i); scanf("%f",&a[i]); } printf("Mang vua nhap: "); min=a[0]; for(i=0;i<n;i++) { printf("%.2f ",a[i]); if(a[i]< min) min=a[i]; } printf("\nGia tri nho nhat cua day la: %.2f",min); for(i=0;i<n;i++) if(a[i]==min) t=t+1; printf("\nSo luong phan tu bang gia tri nho nhat la: %d",t); getch(); } Đề 5 #include <conio.h> #include <stdio.h> #include <math.h> int main() { int N,i,j,k=0,h=0,a[10]; do { printf("\n Nap mot so nguyen N: "); scanf("%d",&N); if(N<=0 || N>=10) printf(" Xin moi nhap lai\n"); } while(N<=0 || N>=10); for(i=0;i<N;i++) {printf("\n Nhap gia tri a[%d] = ",i); scanf("%d",&a[i]);} printf(" Cac phan tu trong mang:\n"); for(i=0;i<N;i++) {printf("%3d",a[i]);} for(i=0;i<N;i++) { k=0; for(j=1;j<=a[i];j++) { if(a[i]%j==0) k++; } if(k==2 && a[i]!=1) {printf("\n %d",a[i]);h++;} } printf("\n So luong so nguyen to co trong day la: %d",h); } Đề 6 #include<stdio.h> #include<conio.h> main(){ int N; do{ printf("Nhap N: "); scanf("%d",&N); }while(N<1 || N>10); int A[N], i, sum = 0, count = 0; for(i=0;i<N;i++){ printf("Nhap A%d: ",i+1); scanf("%d",&A[i]); if(A[i]%2==0){ sum += A[i]; count++; } } if(count){ printf("Trung binh cong cua cac so chan co trong day la: %f",1.0*sum/count); }else{ printf("Mang vua nhap khong co so chan nao"); } getch(); } Đề 7 #include <stdio.h> #include <conio.h> int main() { int a[15],n,s,dem; do { printf("Moi nhap n (1<=n<=10) n="); scanf("%d",&n); } while (n<1 || n>10); dem=0; for(int i=1;i<=n;i++) { printf("a[%d]=",i); scanf("%d",&a[i]); if (a[i]%2==1) { s+=a[i]; dem++; }; } for(int i=1;i<=n;i++) printf("%d ",a[i]); printf("\n"); float tbc; //printf("xx %d %d\n",s,dem); tbc=1.0*s/dem; printf("trung binh cong cua cac so le trong day la %f",tbc); getch(); } Đề 8 #include <stdio.h> #include <conio.h> int main() { int N,a[10],i,dem=0; float tbc,s=0; printf("Nhap vao so nguyen N trong khoang tu 0 den 10 \nN="); scanf("%d",&N); do { if(N>=10||N<=0) { printf("Nhap lai N thoa man yeu cau tren \nN="); scanf("%d",&N); } } while(N>=10||N<=0); for(i=0;i<N;i++) { printf("Nhap vao phan tu thu %d cua mang ",i+1); scanf("%d",&a[i]); if(a[i]%3==0&& a[i]%2!=0) { s+=a[i]; dem++; } } printf("Mang vua nhap la"); for (i=0;i<N;i++) printf(" %d",a[i]); if(dem==0) printf("\nMang vua nhap khong co so nao chia het cho 3 va khong chia het cho 2"); else { tbc=s/dem; printf("\nTrung binh cong cua cac so chia het cho 3 va khong chia het cho 2 la %f",tbc); } getch(); } Đề 9 #include<stdio.h> #include<conio.h> main(){ int N; do{ printf("Nhap N: "); scanf("%d",&N); }while(N<1 || N>10); int A[N], i, sum = 0, count = 0; for(i=0;i<N;i++){ printf("Nhap A%d: ",i+1); scanf("%d",&A[i]); if(A[i]%10==5){ sum += A[i]; count++; } } printf("Mang da nhap vao: "); for(i=0;i<N;i++){ printf("%d ",A[i]); } if(count){ printf("\nTrung binh cong cua cac so chia het cho 5 nhung khong chia het cho 10 la: %f",1.0*sum/count); }else{ printf("\nMang vua nhap khong co so nao chia het cho 5 nhung khong chia het cho 10"); } getch(); } Đề 10 #include <stdio.h> #include <conio.h> int Tonguoc(int a) { int j,S; S=0; for (j=1;j<=a;j++) if ((a%j)==0) S=S+j; return S; } int main() { int a[15],b[15],N,i,dem; do { printf(" \n Nhap so luong phan tu mang (N?): "); scanf("%d",&N); if ((N<=0)||(N>=10)) printf(" YEU CAU NHAP LAI!"); } while ((N<=0)||(N>=10)); printf(" Nhap cac tu trong mang: "); for (i=1;i<=N;i++) { printf("\n Nhap phan tu [%d]: ",i); scanf("%d",&a[i]); } printf(" Mang vua nhap: "); for (i=1;i<=N;i++) printf("%5d",a[i]); for (i=1;i<=N;i++) b[i]=0; dem=0; for (i=1;i<=N;i++) if((a[i]>0)&&(Tonguoc(a[i])==(2*a[i]))) { dem++; b[i]=1; } printf("\n So luong cac so hoan thien trong mang: %d",dem); if (dem!=0) { printf("\n Cac so do la: "); for (i=1;i<=N;i++) if (b[i]==1) printf("%5d",a[i]); } getch(); } Đề 11 #include<stdio.h> #include<conio.h> #include<math.h> int main() { float pi,epsilon,i; printf("Nhap epsilon (0<epsilon<1): "); scanf("%f",&epsilon); i=0;pi=0; while((1/(2*i+1))>epsilon) { pi+=4*(pow((-1),i)*1/(2*i+1)); i++; } printf("\n PI= %.5f",pi); getch(); return 0; } Đề 12 #include<stdio.h> #include<conio.h> #include<math.h> int main() { float a,b,c,dt; printf("\n Nhap vao ba so a:"); scanf("%f",&a); printf("\n Nhap vao ba so b:"); scanf("%f",&b); printf("\n Nhap vao ba so c:"); scanf("%f",&c); if(a==0) { if(b==0) { if(c==0) printf("\n Phuong trinh co vo so nghiem"); else printf("\n phuong trinh vo nghiem"); } else printf("\n Phuong trinh co mot nghiem x= %f",c/b); } else {dt=b*b-4*a*c; if(dt==0) printf("\n phuong trinh co nghiem kep x1= x2 = %f",-b/(2*a)); else if(dt>0) printf("\n phuong trinh co hai nghiem x1=%f, x2=%f",-b-sqrt(dt)/(2*a),- b+sqrt(dt)/(2*a)); else printf("\n Phuong trinh co hai nghiem phuc la\n x1= %f - %f*i, x2= %f + %f*i",-b/ (2*a),sqrt(fabs(dt))/(2*a),-b/(2*a),sqrt(fabs(dt))/(2*a));} getch(); } Đề 13 #include<stdio.h> #include<conio.h> main() { int N,i,j,S,S1,tong=0,a[100],k=0; do { printf("\n Nhap vao so nguyen N(0<N<1000): "); scanf("%d",&N); if(N<=0||N>=1000) printf("\n So ban nhap khong dung yeu cau, hay nhap lai!"); } while(N<=0||N>=1000); printf("\n Cac so hoan thien trong khoang tu 0 den N la: "); for(i=1;i<N;i++) { S=0; for(j=1;j<=i;j++) { if(i%j==0) { S+=j; } } if(S==2*i) { printf("%5d",i); tong+=S; } } printf("\n Tong cac so hoan thien trong khoang tu 0 den N la %d",tong/2); getch(); return 0; } Đề 14 #include<stdio.h> #include<conio.h> int main() { int n,i,j,dem,s=0; do{printf("nhap so nguyen n = "); scanf("%d",&n); if(n<=0||n>=200) {printf("so khong hop le.vui long nhap lai!\n"); } }while(n<=0||n>=200); if(n==1||n==2) {printf("khong co so nguyen to nao trong khoang 0 den %d",n); } else { printf("\ncac so nguyen to trong khoang tu 0 den %d la: ",n); for(i=2;i<n;i++) {dem=0; for(j=2;j<n;j++) { if(i%j==0) { dem++;}} if(dem==1){ printf("%4d",i); s+=i; }} printf("\ntong cac so nguyen to la: %d",s);} getch(); }