Câu 1. vi t ct nh p m ng n ph n t s nguy ên, d m, tính t ng v à li t k ê các s nguyên t trong m ng. #include <iostream.h> # include <math.h> void main (){ int n,i,a[100],s=0,d=0; cout<<"Nhap vao gia tri cua n :"; cin>>n; for(i=0;i<n;i++){ cout<<"a["<<i<<"]= "; cin>>a[i]; } cout<<"Cac so nguyen to co trong mang : "<<endl; for(i=0;i<n;i++){ int k=2; while(a[i]%k!=0&&k<=sqrt(a[i]))k++; if(sqrt(a[i])<k){ d++; s+=a[i]; cout<<"a["<<i<<"]="<<a[i ]<<endl;}} if(d!=0){ cout<<"Co "<<d<<" so nguyen to trong mang ! "<<endl; cout<<"Tong cac so nguyen to trong mang la : "<<s; } else cout<<"Ko co so nguyen to nao trong mang ! "; } Câu 2. nhu trên s chính ph uong. # include <iostream.h> # include <math.h> void main (){ int n,i,a[100],d=0,t=0; cout<<"Nhap vao so phan tu cua mang : ";cin>>n; cout<<"nhap mang : "<<endl; for(i=0;i<n;i++){ cout<<"a["<<i<<"]= "; cin>>a[i]; } cout<<"Cac so chinh phuong trong mang : "<<endl; for(i=0;i<n;i++){ int k=sqrt(a[i]); if(k*k==a[i]){ d++;t+=a[i]; cout<<a[i]<<" ; "; } } if(d>0){ cout<<" \ nCo "<<d<<" so chinh phuong trong mang tren ! "<<endl; cout<<"Tong S = "<<t; } else cout<<"Khong co so chinh phuong nao trong mang tren ! "; } Câu 3. Vi t ct nh p m ng n ph n t s nguy ên, nh p ph n t c n t ìm ki m M n u tìm th y thông báo s lu ng v à v trí c a nh ng ph n t t ìm th y ngu c l i thông báo không tìm th y #include <iostream.h> void main (){ int n,i,m,d=0,vt; int a[100]; co ut<<"Nhap vao gia tri cua n : "; cin>>n; for(i=0;i<n;i++){ cout<<"a["<<i<<"]= "; cin>>a[i]; } cout<<"Nhap vao phan tu M can tim kiem :"; cin>>m; for(i=0;i<n;i++){ if(a[i]==m)d++; } if(d!=0){ cout<<"Co "<<d<<" phan tu "<<m <<" trong mang vua nhap ! "<<endl; cout<<"Vi tri xuat hien : "; for(i=0;i<n;i++){ if(a[i]==m) cout<<"a["<<i<<"]"<<" ; "; } } else cout<<"Khong xuat hien phan tu "<<m<<" trong mang vua nhap ! ";} Câu 4. vi t ct nh p m ng n ph n t in ra các s l theo th t tr tuy t d i tang d n, các s ch n theo th t tuy t d i gi m d n # include <iostream.h> #include <math.h> void main (){ int a[100],i,n,j,tg; cout<<"Nhap vao gia tri cua n : "; cin>>n; for(i=0;i<n;i++){ cout<<"a["<<i<<"]= "; cin>>a[i]; } for(i=0;i<n - 1;i++) for(j=i+1;j<n;j++){ if(a[i]%2==0&&a[j]%2==0&&abs(a[i])<abs(a[j])){ tg=a[i];a[i]=a[j];a[j]=tg; } if(a[i]%2!=0&&a[j]%2!=0&&abs(a[i])>abs(a[j])) { tg=a[i];a[i]=a[j];a[j]=tg; } } cout<<"cac so le : "<<endl; for(i=0;i<n;i++){ if(a[i]%2!=0) cout<<a[i]<<" , "; } cout<<" \ nCac so chan la : "<<endl; for(i=0;i<n;i++){ if(a[i]%2==0) cout<<a[i]<<" , "; } } Câu 5. nh p xâu ký t t b àn phím d m trong xâu ký t nào xu t hi ên nhi u nh t #include <iostream.h> #include <string.h> void main (){ int a[256]={0},i=0,max=0; char s[100]; cout<<"Nhap vao Xau : "; cin.getline(s,100); while(s[i]!=' \0 ')a[s[i++]]++; for(i=0;i<256;i++) if(max<a[i])max=a[i]; for(i=0;i<256;i++) if(max==a[i]) cout<<"'"<<(char)i<<"' ,"; cout<<endl<<"Xuat hien : "<<max<<" lan !"; } Câu 6. nh p xâu. In ra ký t d ài nh t trong xâu #include <iostream.h > #include <string.h> void main (){ char s[100]; cout<<"Nhap Xau :"; cin.getline(s,100); int i=0,b,c,d=0,e,k; do{ while(s[i]==' '&&s[i]!=' \ 0')i++; b=i; while(s[i]!=' '&&s[i]!=' \ 0')i++; c=i; if(d<c - b)d=c - b; } while(s[i]!=' \ 0'); i=0; do{ while(s[i]==' '&&s[i]!=' \ 0')i++; b=i; while(s[i]!=' '&&s[i]!=' \ 0')i++; c=i; e=c - b; if(d==e){ for(k=b;k<c;k++) cout<<s[k]; } cout<<endl; } while(s[ i]!=' \ 0'); } Câu 7. nh p xâu chu n hóa xâu dó lo i b các d u cách th a trong xâu d êm trong xâu có bao nhiêu ký t #include<iostream.h> #include <string.h> void main (){ char s[100],d[100]; int dau,cuoi,i,j=0,t=0; cout<<"Nhap xau :"; cin.getline(s,100); dau=0; while(s[dau]==' ')dau++; cuoi= strlen(s) - 1; while(s[cuoi]==' ')cuoi ; cout<<"Xau chuan hoa :"; for(i=dau;i<=cuoi;i++){ if(!((s[i]==' ')&&(s[i+1]==' '))) { d[j]=s[i]; cout<<d[j]; if(d[j]==' ')t++; j++; } } cout<<" \ nCo "<<t+1<<" tu trong xau tren !"; } Câu 8. nh p m ng n sinh vi ên g m các thông tin; t ên gi i tính, di m toán, lý , hóa. In danh sách s th t các sv n b l i theo th t tang d n c a t ng di m. # include<iostream.h> # include<string.h> struct sv{ char ten[30], gt[5]; float t,l,h; } a[70],tg; void main(){ int n,i,j,d=0; cout<<"Nhap so luong SV :"; cin>>n; for(i=1;i<=n;i++){ cin.ignore(); cout<<"SV thu "<<i<<" : "<<endl; cout<<"Ho va Ten : "; cin.getline(a[i].ten,30); cout<<"Gioi tinh : "; cin.getline(a[i]. gt,5); cout<<"Diem toan : ";cin>>a[i].t; cout<<"Diem ly : ";cin>>a[i].l; cout<<"Diem hoa : ";cin>>a[i].h; } float ti,tj; for(i=1;i<=n - 1;i++) for(j=i+1;j<=n;j++){ ti=a[i].t+a[i].l+a[i].h; tj=a[j].t+a[j].l+a[j].h; if(ti>tj ){ tg=a[i];a[i]=a[j];a[j]=tg;} } for(i=1;i<=n;i++) if(!(strcmp(a[i].gt,"nu"))&&(a[i].t<4||a[i].l<4||a[i].h<4)) { d++; cout<<d<<" : "<<a[i].ten<<" : "<<(ti=a[i].t+a[i].l+a[i].h)<<endl; } } Câu 10. Vi t ct tính giá tr c a da th c n n n n nn axaxaxaxp 1 1 1 )( T i giá tr x b c n, giá tr x v à các h s c a da th c nh p t b àn phím . # include <iostream.h> void main (){ int a[100],i,n,x,p=0,t=1; cout<<"Nhap vao gia tri cua n : "; cin>>n; cout<<"Nhap vao mang : "<<endl; for(i=0;i<n;i++){ cout<<"a["<<i<<"]= "; cin>>a[i]; } cout<<"Nhap vao gia tri cua X : "; cin>>x; for(i=0;i<n;i++){ p+=a[i]*t; t*=x; } cout<<"Gia tri cua P("<<x<<")= "<<p; } This document was created with Win2PDF available at http://www.win2pdf.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only. This page will not be added after purchasing Win2PDF. . t*=x; } cout<<"Gia tri cua P("<<x<<")= "<<p; } This document was created with Win2PDF available at http://www.win2pdf.com. The unregistered version