Matrix Multiplication Using Function

Matrix Multiplication Using Function in C

Matrix Multiplication Using Function in C programming is a very important concept.It can be done by using the simple concept of function.Function is not a main function.The function,we are talking here about the user defined function

`void mul_mat(int A[M][N],int B[M][N],int C[M][N],int s,int t,int u,int v);`

This is called the function declaration which is done before the main function in Matrix Multiplication Using Function in C programming Language

In side the main function, we have declared three 2 dimensional arrays.Out of the three matrices, two matrices are used for storing the input matrices and one is used as output matrix ,but we have not done any mathmatical calculation over here.So, we have passed all these matrices to the user defined function called mul_mat()

In Matrix Multiplication Using Function in C, all the required tasks are performed in mul_mat().

`mul_mat(a,b,c,m,n,p,q);`

which is a calling function inside the main function.The task of the calling function is to call the called function.Called function is defined outside the main function.Now, all the required tasks are proceeded inside of it.

All the required logics are given inside the user defined function.The value of matrices a,b and c are assigned to matrices A,B and C in called functions.The size of input matrices are also sent to the called function from the calling functions respectively.

Inside the called function, first of all, the order of the first input matrix and second input matrix is compared. if the column of the first matrix is not equal with the row of the second matrix, then the calculatation can not be done.So,it throws the error message.if the order is matched, then the further calculatation can be done.

Codes of Matrix Multiplication Using Function
```#include
#include
#define M 10
#define N 10
void mul_mat(int A[M][N],int B[M][N],int C[M][N],int s,int t,int u,int v);
void main()
{
int a[M][N],b[M][N],c[M][N];
int i,j;//for indexing
int m,n,p,q;
clrscr();
printf("\nEnter the rows and columns of first matrix:");
scanf("%d%d",&m,&n);
printf("\nEnter the rows and columns of second matrix");
scanf("%d%d",&p,&q);
printf("\nEnter the first matrix:");
for(i=0;i
Called Function in Matrix Multiplication Using Function
void mul_mat(int A[M][N],int B[M][N],int C[M][N],int s,int t,int u,int v)
{
int i,j,k;
if(t!=u)
{
printf("\nNot possible");
exit(0);
}
else
{
for(i=0;i

This is the example for function implementation, and you can create your own function to implement the matrix implementation.

// <![CDATA[
// ]]&gt;
Q. Write a program to evaluate the series until the last term becomes less than 10^-6.
The given series is following
Sn=1+x/1!+x^2/2!.....
#include
#include
#include
long int fact(int);
void main()
{
int x,i=0; //for input
float term=0,sum=0;
long int f;
clrscr();
printf("\nEnter the value of x:\n");
scanf("%d",&x);
do
{
term=pow(x,i)/(float)fact(i);
sum=sum+term;
i++;
}while(term <=pow(10,-5));
sum=sum-term;

printf("\nThe sum of the series is %.2f",sum);
printf("\nThe last term is %f",term);
printf("\nThe total number of terms is %d",i-1);
getch();
}
long int fact(int m)
{
int i;
long int f=1;
for(i=2;i<=m;i++)
{
f=f*i;
}
return f;
}

The result of the following code is shown below:
Sum of the series