Skip to content

Instantly share code, notes, and snippets.

@Valindo
Created February 7, 2016 15:35
Show Gist options
  • Save Valindo/f6d268142ac57a1588fb to your computer and use it in GitHub Desktop.
Save Valindo/f6d268142ac57a1588fb to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<conio.h>
void addition(float a[][3],float b[][3],int n)
{
int i,j;
float c[3][3];
printf("The value of addition of two matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%.2f\t",c[i][j]);
}
printf("\n");
}
}
void subtraction(float a[][3],float b[][3],int n)
{
int i,j;
float c[3][3];
printf("The value of subtraction of two matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("%.2f\t",c[i][j]);
}
printf("\n");
}
}
void multiplication(float a[][3],float b[][3],int n)
{
int i,j,p;
float c[3][3];
printf("The value of multiplication of two matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
for(p=0;p<n;p++)
c[i][j]+=a[i][p]*b[p][j];
printf("%.2f\t",c[i][j]);
}
printf("\n");
}
}
void main()
{
float a[3][3],b[3][3];
int i,j,n;
char ch;
printf("Addition->+\nSubtraction->-\nMultiplication->*\n");
printf("Enter your choice:");
scanf("%c",&ch);
printf("\nEnter the matrix of size n x n:");
scanf("%d",&n);
printf("\nEnter the value of matrix 'a':");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\na[%d][%d]:",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
printf("\nEnter the value of matrix 'b':");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\nb[%d][%d]:",i+1,j+1);
scanf("%f",&b[i][j]);
}
}
switch(ch)
{
case '+':addition(a,b,n);
break;
case '-':subtraction(a,b,n);
break;
case '*':multiplication(a,b,n);
break;
default:printf("Wrong choice");
}
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment