Addition,Substrction ,Multiplication And Compare of two Matrix
//Brijesh
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100][100],b[100][100],add[100][100],sub[100][100],mul[100][100],r,c;
int i,j,flag=0;
clrscr();
printf("enter the size of matrix (ROW AND COL)\n");
scanf("%d%d",&r,&c);
printf("Enter the element into matrix\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the element into 2nd matrix\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
//for addition
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
add[i][j]=a[i][j]+b[i][j];
}
}
printf("Addition\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%5d",add[i][j]);
}
printf("\n");
}
//substraction
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
sub[i][j]=a[i][j]-b[i][j];
}
}
printf("Substraction\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%5d",sub[i][j]);
}
printf("\n");
}
//multiplication
//substraction
printf("Multiplication\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(int k=0;k<r;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
printf("%5d",mul[i][j]);
}
printf("\n");
}
//compare of two matrix
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]==b[i][j])
flag=1;
}
}
if(flag==1)
printf("same");
else
printf("not same");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100][100],b[100][100],add[100][100],sub[100][100],mul[100][100],r,c;
int i,j,flag=0;
clrscr();
printf("enter the size of matrix (ROW AND COL)\n");
scanf("%d%d",&r,&c);
printf("Enter the element into matrix\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the element into 2nd matrix\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
//for addition
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
add[i][j]=a[i][j]+b[i][j];
}
}
printf("Addition\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%5d",add[i][j]);
}
printf("\n");
}
//substraction
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
sub[i][j]=a[i][j]-b[i][j];
}
}
printf("Substraction\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%5d",sub[i][j]);
}
printf("\n");
}
//multiplication
//substraction
printf("Multiplication\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(int k=0;k<r;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
printf("%5d",mul[i][j]);
}
printf("\n");
}
//compare of two matrix
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]==b[i][j])
flag=1;
}
}
if(flag==1)
printf("same");
else
printf("not same");
getch();
}
No comments
Post a Comment