Two dimensional Array
Two dimensional array syntax
datatype variablename arraylenth;
Ex:-
int a[][];
int a[10][10],b[10][10];
/* Sum of all the elements in the matrix */
#include<stdio.h>
main()
{
int j,k,a[2][2],sum=0;
printf("\nEnter the elements for matrix a:");
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
printf("\nEnter a[%d][%d]:",j,k);
scanf("%d",&a[j][k]);
}
}
printf("\n the matrix is...:\n");
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
printf("\t%d",a[j][k]);
sum=sum+a[j][k];
}
printf("\n");
}
printf("\nthe sum of all elements in the matrix is:%d",sum);
}
0 comments:
Post a Comment