#include<stdio.h>
void matmultiply(int m[3][3], int n[3][3]);
void read(int x[3][3]);
//void read2(int y[3][3]);
void main()
{
int a[3][3],b[3][3],l,w;
printf("\nFor matrix a :-\n");
read(a);
printf("\nFor matrix b :-\n");
read(b);
printf("\nMatrix a :\n");
for(l=0;l<3;l++)
{
for(w=0;w<3;w++)
{
printf("%d\t",a[l][w]);
}
printf("\n");
}
printf("\nMatrix b :\n");
for(l=0;l<3;l++)
{
for(w=0;w<3;w++)
{
printf("%d\t",b[l][w]);
}
printf("\n");
}
matmultiply(a,b);
getch();
}
void read(int x[3][3])
{
int r,s;
for(r=0;r<3;r++)
{
for(s=0;s<3;s++)
{
printf("Enter the [%d][%d]th element of matrix : ",r,s);
scanf("%d",&x[r][s]);
}
}
}
void matmultiply(int m[3][3], int n[3][3])
{
int t[3][3],i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
t[i][j]=0;
for(k=0;k<3;k++)
{
t[i][j]=t[i][j]+m[i][k]*n[k][j];
}
}
}
printf("\nThe resultant matrix after multiplying is :-\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",t[i][j]);
}
printf("\n");
}
}
Monday, July 31, 2017
Home »
C Programming
» Code in C to multiply two matrix
Code in C to multiply two matrix
Related Posts:
Operations on complex numbers in C#include<stdio.h> struct cmplx { float real; float img; }; struct cmplx add(struct cmplx x, struct cmplx y) { struct cmplx z; z.real = x.real + y.real; &nbs… Read More
Count no. of words in a sentence in C#include<stdio.h> void main() { char str[50],i,wordcount=0; printf("Enter a line of text : "); gets(str); for(i=0;str[i]!='\0';i++) { &… Read More
Display string after deleting vowels in it in C#include<stdio.h> void main() { char str[50],i; printf("Enter a string : "); gets(str); printf("\nAfter deleting vowels :\t"); for(i=0;str[i]!='\0'… Read More
Find largest and smallest no. in C#include<stdio.h> void main() { int x[10],i,j,temp; for(i=0;i<=9;i++) { printf("Enter %dth number : ",i+1); scanf("%d"… Read More
Arranging numbers in ascending and descending order in C#include<stdio.h> void main() { int x[5],i,j,temp; for(i=0;i<=4;i++) { printf("Enter x[%d]th number : ",i); scanf("%d"… Read More
0 comments:
Post a Comment