What is array? write a program to add two matrices?

Answers (1)

Array is a collection of similar elements. These similar elements could be all ints, or all floats, or all chars, etc. Usually, the array of characters is called a string, whereas an array of ints or floats is called simply an array. Remember that all element of an given array must be of same type. i.e., we cannot have an array of 10 numbers, of which 5 are ints and 5 are floats.

#include<stdio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
printf("\n Enter the A matrix:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n Enter the B matrix:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n Output is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",c[i][j]);
}
}
}

Votes: +0 / -0