//code Dung NV tich hai ma tran
#include <stdio.h>
#include <conio.h>
void nhap(float a[][50],int x,int y)
{
int i,j;
for (i=0;i<x;i++)
for (j=0;j<y;j++)
{
printf("nhap phan tu [%d][%d] : ",i,j);
scanf("%f",&a[i][j]);
}
}
void xuat(float a[][50],int x,int y)
{
int i,j;
for (i=0;i<x;i++)
{
for (j=0;j<y;j++)
printf(" %5.2f ",a[i][j]);
printf("\n");
}
}
void tichmatran(float a[][50],floatb[][50],float c[][50],intx,int y,int z)
{
int i,j,k;
float s;
for (i=0;i<x;i++)
for (j=0;j<z;j++)
{
s=0;
for (k=0;k<y;k++) s+=a[i][k]*b[k][j];
c[i][j]=s;
}
}
void main()
{
int m,n,p;
float a[50][50],b[50][50],c[50][50];
printf("nhap m,n,p = ");
scanf("%d%d%d",&m,&n,&p);
printf("nhap mang a : \n");
nhap(a,m,n);
printf("nhap mang b : \n");
nhap(b,n,p);
printf("\n mang a \n");
xuat(a,m,n);
printf("\n mang b \n");
xuat(b,n,p);
tichmatran(a,b,c,m,n,p);
printf("\n mang c = a X b \n");
xuat(c,m,p);
getch();
}
No comments:
Post a Comment