SLIDE1

Thursday, September 25, 2014

chương trình c tính tích hai 2 ma trận bất kì


/*chuong trinh c tinh tich hai ma tran bat ki*/
#include<stdio.h>
#include<conio.h>
#define max 100
/*tao ham nhap ma tran*/
void nhap(int mt[max][max],int h,int c)
{
printf("nhap ma tran:\n _____________________________\n");
for (int i = 0; i < h; i++)
{
printf("nhap hang %d:\n",i+1);
for (int j = 0; j < c; j++)
{
scanf_s("%d", &mt[i][j]);
}
printf("\n");
}
}
/*tao ham xuat ma tran*/
void xuat(int mt[max][max], int h, int c)
{
printf("__________________________\n");
for (int i = 0; i < h; i++)
{
for (int j = 0; j < c; j++)
{
printf("%6d", mt[i][j]);
}
printf("\n");
}
}
int mt1[max][max];
int mt2[max][max];
int tich[max][max];
void main()
{
printf("________author: Tran Khanh Toan____________\n___________________________\n");
int h1, h2, c1, c2;
/*nhap ma tran 1*/
printf(">>>ma tran 1\n");
printf("nhap so hang: ");
scanf_s("%d", &h1);
printf("nhap so cot: ");
scanf_s("%d", &c1);
nhap(mt1, h1, c1);
/*nhap ma tran 2*/
printf("\n__________________________________\n >>>ma tran 2\n");
printf("nhap so hang: ");
scanf_s("%d", &h2);
printf("nhap so cot: ");
scanf_s("%d", &c2);
nhap(mt2, h2, c2);
/*kiem tra hai ma colien hop khong
neu khong lien hop thi ket thuc chuong trinh*/
if (c1 != h2)
{
printf("hai ma tran khong lien hop nen khong the tinh tich");
goto kt;
}
/*tinh tich 2 ma tran*/

for (int i = 0; i < h1; i++)
{
for (int j = 0; j < c2; j++)
{
for (int n = 0; n < c1; n++)
{
tich[i][j] += mt1[i][n] * mt2[n][j];
}
}
}
printf("\n ________________________\n tich 2 ma tran do la: \n");
xuat(tich, h1, c2);
kt:;

_getch();
}
/* a(i,1)*b(1,j)+a(i,2)*b(2,j)=c(i,j)    */
file chương trình,>>>>> click to dwnload