la chinh minh_ban nhe! Nhập Môn
Tổng số bài gửi : 13 Join date : 23/07/2009 Age : 33 Đến từ : Cà Mau
| Tiêu đề: Một số bài tập dành cho các bạn thi lại môn cơ sở lập trình nè! Fri Jul 24, 2009 10:59 am | |
| | | | | bài này là NHÂN MA TRẬN nha!
#include"conio.h" #include"stdio.h" #include"iostream.h" #define hang 20 #define cot 20 void nhapmt(float a[hang][cot],int m,int n) { for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } } } void xuatmt(float a[hang][cot],int m,int n) { for(int i=0;i<m;i++) { cout<<"\t"<<endl; for(int j=0;j<n;j++) { cout<<"\t"<<a[i][j]; } } } void nhan(float a[hang][cot],int m,int n,float b[hang][cot],int p,int q,float c[hang][cot]) { if(n==p) for(int i=0;i<m;i++) { for(int j=0;j<q;j++) { c[i][j]=0; for(int k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } void main() { clrscr(); float a[hang][cot],b[hang][cot],c[hang][cot]; int m,n,p,q; cout<<"Nhap Ma Tran a\n"; cout<<"Nhap so hang m="; cin>>m; cout<<"Nhap so cot n="; cin>>n; nhapmt(a,m,n); xuatmt(a,m,n); cout<<"\nNhap ma tran b\n"; cout<<"Nhap so hang p="; cin>>p; cout<<"Nhap so cot q="; cin>>q; nhapmt(b,p,q); xuatmt(b,p,q); if(n!=p) { cout<<"Khong Giai Duoc Tich 2 Ma Tran "; } else { cout<<"\nTich Ma Tran a*b La \n"; nhan(a,m,n,b,p,q,c); xuatmt(c,m,n); } getch(); }
bài này là CỘNG MA TRẬN nha!
#include <stdio.h> #include <conio.h> #define max 100 void nhap(int &m,int &n) { do { printf("nhap m va n:"); scanf("%d %d",&m,&n); }while(m!=n); } void nhap(float a[max][max],int m,int n) {
for(int i=0;i<m;i++) for(int j=0;j<n;j++) { printf("\n nhap a[%d][%d]:",i,j); scanf("%f",&a[i][j]); } } void xuat(float a[max][max],int m,int n) { for(int i=0;i<m;i++) { printf("\n"); for(int j=0;j<n;j++) printf("%5.2f",a[i][j]); } } void congMt(float a[max][max],float b[max][max],float c[max][max],int m,int n) { /* if(m!=m||n!=n) printf("\n tb khong cong duoc");*/ for(int i=0;i<m;i++) for(int j=0;j<n;j++) c[i][j]=a[i][j]+b[i][j]; } void main() { clrscr(); float a[max][max],b[max][max],c[max][max]; int m,n; nhap(m,n); nhap(a,m,n); xuat(a,m,n); nhap(b,m,n); xuat(b,m,n); congMt(a,b,c,m,n); printf("\n ma tran sau khi cong la:"); xuat(c,m,n); getch(); } | | | | |
|
|
nguyenthanhvu Thành viên cấp 5
Tổng số bài gửi : 300 Join date : 09/05/2009 Đến từ : CNTT2_K9
| Tiêu đề: Re: Một số bài tập dành cho các bạn thi lại môn cơ sở lập trình nè! Fri Jul 24, 2009 6:12 pm | |
| |
|