Admin Admin
Tổng số bài gửi : 165 Join date : 14/09/2008 Age : 31 Đến từ : Quảng Ninh
| Tiêu đề: Đề + lời giải môn KTLT Sat Oct 08, 2011 5:39 am | |
| đề: lời giải:Kéo xuống để đọc. - Code:
-
Câu 1: #include<iostream.h> #include<math.h> #include<conio.h> int F(int x, float n) { int t=0,i; if(n>1)for(i=n;i>=0;i++) { t+=x/i; return t; } else return abs(n)+2011; } void main() { int a; float r,S; cout<<"Nhap so nguyen a: "; cin>>a; cout<<"Nhap so thuc r: ";cin>>r; S=F(a,r)+log(fabs(r)); cout<<"Gia tri cua bieu thuc la: "<<S; getch(); }
Câu 2:
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { int A[20],n,i,x,tong,dem; cout<<"Nhap so phan tu n= "; cin>>n; cout<<"Nhap mang so nguyen "; for(i=0;i<n;i++) { cout<<"A["<<i<<"]="; cin>>A[i]; } cout<<"mang vua nhap: "<<endl; cout<<A[i]<<" "; //in ra man hinh cac so le va tong cua chung tong=0; dem=0; cout<<"Cac so le co trong mang: "; for(i=0;i<n;i++) if(A[i]%2!=0){ tong+=A[i]; cout<<A[i]<<" "; dem++; } cout<<"Cac so le trong mang: "<<tong<<endl; if(dem!=0){ tbc=tong/dem; cout<<"TBC cac so le trong mang "<<tbc<<endl; } else cout<<"mang khong co so le nao "<<endl; //Nhap so nguyen x, xoa cac so bang x trong day, in day sau khi xoa cout<<"Nhap so nguyen x: "; cin>>x; i=0; while(i<n) if(A[i]==x) { for(int j=i; j<n-1; j++) A[j]=A[j+1]; n--; } else i++; cout<<"Mang sau khi xoa: "; for(i=0;i<n;i++) cout<<A[i]<<" "; getch(); }
Câu 3:
#include<iostream.h> #include<stdio.h> #include<conio.h> int MT{ char hangsx[50],nhan[30]; float giatien,tocdo; } void nhapds(MT M[],int n) { for(int i=0;i<n;i++) { cout<<"Nhap may tinh thu: "<<(i+1)<<endl; cout<<"Nhan hieu: ";fflush(stdin);gets(M[i].nhan); cout<<"Hang sx: ";fflush(stdin);gets(M[i].hangsx); cout<<"gia tien: ";cin>>M[i].giatien; cout<<"Toc do cpu: ";cin>>M[i].tocdo; } } void hienthi(MT M[],int n) { for(int i=0; i<n; i++) { cout<<"Thong tin may tinh thu: "<<(i+1)<<endl; cout<<"Nhan hieu: "<<M[i].nhan<<endl; cout<<"Hang sx: "<<M[i].hangsx<<endl; cout<<"Gia tien: "<<M[i].giatien<<endl; cout<<"Toc do cpu: "<<M[i].tocdo<<endl; } } void hienthi_IBM(MT M[], int n) { for(int i=0; i<n;i++) if(strcmp(M[i].hangsx,"IBM")==0) { cout<<"Thong tin may tinh thu: "<<(n+1)<<endl; cout<<"Nhan hieu: "<<M[i].nhan<<endl; cout<<"Hang sx: "<<M[i].hangsx<<endl; cout<<"Gia tien: "<<M[i].giatien<<endl; cout<<"Toc do cpu: "<<M[i].tocdo<<endl; } } float tongtien(MT M[],int n) { float t=0; for(i=0;i<n;i++)t+=M[i].giatien; return t; } void sapxep(MT M[],int n) { for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) if(M[i.tocdo<M[j].tocdo) { MT tg=M[i];M[i]=M[j];M[j]=tg; } } void main() { MT M[50]; int n; cout<<"Nhap n: "; cin>>n; cout<<"Danh sach may tinh: "<<endl; nhapds(M,n); cout<<"Danh sach may tinh cua hang IBM: "<<endl; hienthi_IBM(M,n); cout<<"Tong tien la: "<<tongtien(M,n)<<endl; sapxep(M,n); cout<<"Danh sach vua sap xep: "<<endl; hienthi(M,n); getch(); }
| |
|