DẠNG 1*: Mảng 1 chiều Bài 1: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthi(int a[],int n) { for(int i=0;i<n;i++) if(a[i]>5) cout<<a[i]<<"\t"; } void timkiem(int a[],int n) { int dem=0; for(int i=0;i<n;i++) { if(a[i]%3==0) { cout<<a[i]<<" ";dem++; } if(dem==2) break; } } void timsohoanthien(int a[],int n) { int s; for(int i=0;i<n;i++) { s=0; for(int j=1;j<a[i];j++) if(a[i]%j==0) s=s+j; if(s==a[i]) cout<<a[i]<<"\t"; } } void main() { int a[100];int n; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); cout<<"\nCac ptu lon hon 5 la: ";hienthi(a,n); cout<<"\nCac ptu dau tien chia het cho 3 la: ";timkiem(a,n); cout<<"\nCac ptu la so hoan thien la: ";timsohoanthien(a,n); getch(); } Bài 2 #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthi(int a[],int n,int k) { int s=0; for(int i=0;i<n;i++) if(a[i]>k) cout<<a[i]<<" "; else s++; if(s==n) cout<<"Khong co ptu nao thoa man."; } void tinhtong(int a[],int n) { int s=0; for(int i=0;i<n;i++) if(a[i]%3==0&&a[i]%5!=0) s=s+a[i]; cout<<"Tong la: "<<s; } void timsohoanthien(int a[],int n,int k) { int s; for(int i=0;i<n;i++) { s=0; for(int j=1;j<a[i];j++) if(a[i]%j==0) s=s+j; if(s==a[i]&&a[i]>k) cout<<a[i]<<"\t"; } } void main() { int a[100];int n,k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); cout<<"\nCac ptu lon hon "<<k<<": ";hienthi(a,n,k); cout<<"\nTong cac ptu thoa man: ";tinhtong(a,n); cout<<"\nSo hoan thien thoa man: ";timsohoanthien(a,n,k); getch(); } Bài 3: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthi(int a[],int n,int k) { int s=0; for(int i=0;i<n;i++) if(a[i]%k==0) cout<<a[i]<<" "; else s++; if(s==n) cout<<"Khong co ptu nao thoa man."; } void tinhtong(int a[],int n) { int s=0; for(int i=0;i<n;i++) if((i+1)%2==0&&a[i]%2!=0) s=s+a[i]; cout<<"Tong la: "<<s; } void demle(int a[],int n) { int dem=0; for(int i=0;i<n;i++) if(a[i]%2!=0&&a[i]>5) dem++; cout<<"So ptu thoa man la: "<<dem; } void main() { int a[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); cout<<"\nCac ptu chia het cho "<<k<<":";hienthi(a,n,k); cout<<"\n”;tinhtong(a,n); cout<<"\n";demle(a,n); getch(); } Bài 4: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthi(int a[],int n,int k) { int s=0; for(int i=0;i<n;i++) if(a[i]<k) cout<<a[i]<<" "; else s++; if(s==n) cout<<"Khong co ptu nao thoa man."; } void tinhtong(int a[],int n) { int s=0; for(int i=0;i<n;i++) if(a[i]%2==0&&(i+1)%2==0) s=s+a[i]; cout<<s; } void dem(int a[],int n) { int dem=0; for(int i=0;i<n;i++) for(int j=1;j<a[i];j++) if(j*j==a[i]&&(a[i])%2!=0&&(i+1)%2==0) dem=dem+1; cout<<"So ptu thoa man la: "<<dem; } void main() { int a[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); hienthi(a,n,k); cout<<"\nTong cac ptu thoa man la: ";tinhtong(a,n); cout<<"\n";dem(a,n); getch(); } Bài 5: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthi(int a[],int n,int k) { int s=0; for(int i=0;i<n;i++) if(a[i]%k!=0) cout<<a[i]<<" "; else s++; if(s==n) cout<<"Khong co ptu nao thoa man."; } void tinhtong(int a[],int n,int k) { int s=0; for(int i=0;i<n;i++) if(a[i]%k==0) s=s+a[i]; cout<<s; } void dem(int a[],int n) { int s,dem=0; for(int i=0;i<n;i++) { s=0; for(int j=1;j<a[i];j++) if(a[i]%j==0) s=s+j; if(s==a[i]&&a[i]%2==0) dem++; } cout<<dem; } void main() { int a[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); hienthi(a,n,k); cout<<"\nTong cac ptu thoa man la: ";tinhtong(a,n,k); cout<<"\nSo ptu thoa man la: ";dem(a,n); getch(); } Bài 6: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthimang(int a[],int n) { for(int i=0;i<n;i++) cout<<a[i]<<"\n"; } void tinhtong(int a[],int n,int k) { int s=0,dem; for(int i=0;i<n;i++) { dem=0; for(int j=2;j<a[i];j++) if(a[i]%j==0) dem++; if(dem==0&&a[i]<k) s=s+a[i]; } cout<<s; } void demchan(int a[],int n) { int dem=0; for(int i=0;i<n;i++) for(int j=1;j<a[i];j++) if(j*j==a[i]&&a[i]%2==0&&(i+1)%2==0) dem++; cout<<dem; } void main() { int a[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); cout<<"Cac ptu cua mang: "<<"\n";hienthimang(a,n); cout<<"\nTong cac ptu thoa man la: ";tinhtong(a,n,k); cout<<"\nSo ptu thoa man la: ";demchan(a,n); getch(); } Bài 7: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthimang(int a[],int n) { int s=0; for(int i=0;i<n;i++) if(a[i]>=0) cout<<a[i]<<"\t"; else s++; if(s==n) cout<<"Khong co ptu nao thoa man."; } void tinhtong(int a[],int n) { int dem,s=0; for(int i=0;i<n;i++) { dem=0; for(int j=2;j<i;j++) if((i+1)%j==0) dem++; if(dem==0) s=s+a[i]; } cout<<s; } void demnt(int a[],int n) { int dem,dem1=0; for(int i=0;i<n;i++) { dem=0; for(int j=2;j<a[i];j++) if(a[i]%j==0) dem++; if(dem==0&&(i+1)%2!=0) dem1++; } cout<<dem1; } void main() { int a[100];int n; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); hienthimang(a,n); cout<<"\nTong cac ptu thoa man la: ";tinhtong(a,n); cout<<"\nSo ptu thoa man la: ";demnt(a,n); getch(); } Bài 8: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthimang(int a[],int n) { for(int i=0;i<n;i++) cout<<a[i]<<"\n"; } void tinhtongnt(int a[],int n,int k) { int dem,s=0; for(int i=0;i<n;i++) { dem=0; for(int j=2;j<i;j++) if((i+1)%j==0) dem++; if(dem==0&&a[i]<k) s=s+a[i]; } cout<<s; } void demnt(int a[],int n) { int dem,dem1,dem2=0; for(int i=0;i<n;i++) { dem=0;dem1=0; for(int j=2;j<a[i];j++) if(a[i]%j==0) dem++; for(int k=2;k<i;k++) if(i%k==0) dem1++; if(dem1==0&&dem!=0) dem2++; } cout<<dem2; } void main() { int a[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); hienthimang(a,n); cout<<"\nTong cac ptu thoa man la: ";tinhtongnt(a,n,k); cout<<"\nSo ptu thoa man la: ";demnt(a,n); getch(); } Bài 9: #include<iostream.h> #include<conio.h> void nhapmang(int a[],int n) { for(int i=0;i<n;i++) { cout<<"a["<<i<<"]=";cin>>a[i]; } } void hienthimang(int a[],int n) { for(int i=0;i<n;i++) if(a[i]>=0&&a[i]%2==0) cout<<a[i]<<"\t"; } void tinhtongcp(int a[],int n,int k) { int s=0; for(int i=0;i<n;i++) { for(int j=1;j<=a[i];j++) if(j*j==a[i]&&a[i]>k) s=s+a[i]; } cout<<s; } void demnt(int a[],int n,int k) { int dem,dem1=0; for(int i=0;i<n;i++) {dem=0; for(int j=2;j<a[i];j++) if(a[i]%j==0) dem++; if(dem==0&&a[i]<k) dem1++; } cout<<dem1; } void main() { int a[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k; cout<<"Nhap cac ptu cua mang: "<<"\n";nhapmang(a,n); hienthimang(a,n); cout<<"\nTong cac ptu thoa man la: ";tinhtongcp(a,n,k); cout<<"\nSo ptu thoa man la: ";demnt(a,n,k); getch(); } Bài 10: #include<iostream.h> #include<conio.h> void nhapmang(int b[],int n) { for(int i=0;i<n;i++) { cout<<"b["<<i<<"]=";cin>>b[i]; } } void hienthimang(int b[],int n,int k) { for(int i=0;i<n;i++) if(b[i]>k&&b[i]%2==0) cout<<b[i]<<" "; } void saptangle(int b[],int n) { int tg; for(int i=0;i<n-1;i++) for(int m=0;m<n-1;m++) if(b[m]>b[m+1]) { tg=b[m];b[m]=b[m+1];b[m+1]=tg;} for(int j=0;j<n;j++) if(b[j]%2!=0) cout<<b[j]; } void tbcsole(int b[],int n) { int s=0,dem=0;double tbc; for(int i=0;i<n;i++) if(b[i]%2!=0) { dem++;s=s+b[i];} tbc=(double)s/dem; cout<<tbc; } void main() { int b[100];int n;int k; do { cout<<"Nhap n: ";cin>>n; }while(n<=0); cout<<"Nhap k: ";cin>>k;