Skip to main content

Write a program in C to do Vertical Merging of 2 square matrix.


Let's Begin

Basic requirement to understand this program:
1. Matrix
2. Nested looping

Code:-------

#include<stdio.h>
main()
{
int a[3][3],b[3][3];
int i,j,d[3][6];
printf("enter the elements of 1st matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" element [%d][%d]: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("enter the elements of 2nd matrix\n");

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" element [%d][%d]: ",i+1,j+1);
scanf("%d",&b[i][j]);
}
}
int k,l;
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[k][l]==b[i][j])
{ b[i][j]=0;
}
}
}
}
}

printf("vertical merge \n");
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{
d[i][j]=a[i][j];
}
}
for(i=0;i<3;i++)
{for(j=3;j<6;j++)
{
d[i][j]=b[i][j-3];
}
}

for(i=0;i<3;i++)
{
for(j=0;j<6;j++)
{
printf("%3d",d[i][j]);
}
printf("\n");
}


}





Note all codes are written in DEV C++.

Comments