Array program collection in C
/* program to input elements of a
matrix of order 3x3 and print only main diagonal elements
1 2 3
4 5 6
7 8 9
the output would be 1
5
6
*/
#include<stdio.h>
int main()
{
int a[3][3];//array/matrix declaration of size 3x3
int i,j;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("enter element for %d %d location",i,j);
scanf("%d",&a[i][j]);//input for matrix
}
}
for(i=0;i<=2;i++)//it is for row
{
for(j=0;j<=2;j++)//it is for column
{
if(i==j) //condition/logic to print the values
printf("%d",a[i][j]);
else
printf(" "); //printing none if the condition is false
}
printf("\n");
}
return 0;
}