To find sum of 4*5 two matrices
Topics Covered:
- An example of two dimensional array to find 3*4 matrix
- To display the elements of 5*5 matrix
- To read the elements of a matrix and display them where rows and columns are unknown
- To find sum of 4*5 two matrices
- Searching elements in array
//an example of two dimensional array to find 3*4 matrix
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[3][4];
//input section
printf(“enter the elements of matrix\n”);
for(i=0;i<=2;i++)
{
for(j=0;j<=3;j++)
{
printf(“enter the value”);
scanf(“%d”,&a[i][j]);
}
}
//output section
printf(“elements of matrix\n”);
for(i=0;i<=2;i++)
{
for(j=0;j<=3;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
return 0;
}
//to display the elements of 5*5 matrix
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[5][5];
//input section
printf(“enter the elements of matrix\n”);
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
printf(“enter the value”);
scanf(“%d”,&a[i][j]);
}
}
//output section
printf(“elements of matrix\n”);
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
return 0;
}
/*to read the elements of a matrix and display them where rows and columns are unknown*/
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,row,cl,a[10][10];
//input section
printf(“enter the number of rows and column”);
scanf(“%d%d”,&row,&cl);
printf(“enter the elements of matrix\n”);
for(i=0;i<=row-1;i++)
{
for(j=0;j<=cl-1;j++)
{
printf(“enter value”);
scanf(“%d”,&a[i][j]);
}
}
//output section
for(i=0;i<=row-1;i++)
{
for(j=0;j<=cl-1;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
return 0;
}
//to find sum of 4*5 two matrices
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[4][5],b[4][5],c[4][5];
//input section
printf(“enter the elements of first matrix\n”);
for(i=0;i<=3;i++)
{
for(j=0;j<=4;j++)
{
printf(“enter the value”);
scanf(“%d”,&a[i][j]);
}
}
printf(“enter the elements of second matrix\n”);
for(i=0;i<=3;i++)
{
for(j=0;j<=4;j++)
{
printf(“enter the value”);
scanf(“%d”,&b[i][j]);
}
}
//processing section
for(i=0;i<=3;i++)
{
for(j=0;j<=4;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
//output section
printf(“the elements of first matrix\n”);
for(i=0;i<=3;i++)
{
for(j=0;j<=4;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
printf(“the elements of second matrix\n”);
for(i=0;i<=3;i++)
{
for(j=0;j<=4;j++)
{
printf(“%d\t”,b[i][j]);
}
printf(“\n”);
}
printf(“the sum of two matrices\n”);
for(i=0;i<=3;i++)
{
for(j=0;j<=4;j++)
{
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
return 0;
}
//searching elements in array
#include<conio.h>
#include<stdio.h>
int main()
{
int i,a[10]={103,105,106,108,115,116,120,130,133,144},f=0,sn;
printf(“please enter your symbol number”);
scanf(“%d”,&sn);
for(i=0;i<=9;i++)
{
if(sn==a[i])
{
f=1;
}
}
if(f==1)
{
printf(“congratulation! you are passsed”);
}
else
{
printf(“sorry! you are failed”);
}
return 0;
}