Adding and Multiplying 2 Matrices
Adding and Multiplying 2 Matrices
/*
In functions specifieng row size is optional but column size has to be specified.
But in main function the size has to be specified for both row and column.
*/
#include<stdio.h>
#include<stdlib.h>
void mul_matrix(int a[][10], int b[][10], int c[][10], int m, int n, int p, int q)
{
int sum;
if(n != p){
printf("Invalid matrix for multiplication\n\a");
return;
}
int main()
{
int a[10][10], b[10][10], c[10][10];
int m, n, p, q, choice;
printf("1.Add 2 matrix:\n");
printf("2.Multiply 2 matrix:\n\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:printf("Enter size of array(row and column): ");
scanf("%d%d", &m, &n);
enter_value(a, m, n);
enter_value(b, m, n);
add_matrix(a, b, c, m, n);
display(c, m, n);
break;
mul_matrix(a, b, c, m, n, p, q);
display(c, m, q);
break;
default:printf("Invalid choice!\n\a");
break;
}
}