Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by dfsdfs ( 6 years ago )
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void Nhap(double *a , int hang, int cot )
{
for ( int i = 0 ; i < hang; i++)
{
for ( int j = 0 ; j < cot ; j++)
{
scanf ("%lf",(a + i*hang + j));
}
}
}
void Xuat(double *a , int hang, int cot )
{
for ( int i = 0 ; i < hang; i++)
{
for ( int j = 0 ; j < cot ; j++)
{
printf ("%lf ",*(a + i*hang + j));
}
printf ("\n");
}
}
void Tich2matran(double *a, double *b,double *c, int hang, int cot, int n)
{
for ( int i = 0 ; i < hang ; i++)
{
for ( int j = 0; j < cot ; j++)
{
*(c + i*hang + j) = 0;
for ( int k = 0; k < n; k++)
{
*(c + i*hang + j) += *(a + i*hang + k) * *(b + k*hang + j);
}
}
}
}
int main()
{
int hang,cot;
printf ("Nhap vao hang va cot cua ma tran A:");
scanf ("%d%d",&hang,&cot);
int n;
printf ("\nNhap vao cap cua ma tran vuong B:");
scanf ("%d",&n);
double *a,*b,*c;
a = (double* )malloc(hang*cot*sizeof(double));
b = (double* )malloc(n*n*sizeof(double));
c = (double* )malloc(hang*cot*sizeof(double));
printf("\nNhap ma tran A:\n");
Nhap(a,hang,cot);
printf("\nNhap ma tran B:\n");
Nhap(b,n,n);
printf ("\nXuat A:\n");
Xuat(a,hang,cot);
printf ("\nXuat B:\n");
Xuat(b,n,n);
Tich2matran(a,b,c,hang,cot,n);
printf ("\nXuat C:\n");
Xuat(c,hang,cot);
free(a);
free(b);
free(c);
getch();
return 0;
}
Revise this Paste