What if you want to read the second column from the two dimensional array given below. Two for loops – one nested inside will read it.
What about writing it in c??
Here is the program.
#include <stdio.h>
int main()
{
int a[3][4]; //allocate space for 2-dimensional array
int i, j, p;
for(j=0;j<3;j++) // to generate the 2-dimensional table – nested loops
{
for(i=1;i<5;i++)
{
a[j][i]=i;
printf(“%d “, a[j][i]);
}
printf(“\n”);
}
printf(“enter column number: “);
scanf(“%d”,&p);
for(j=0;j<3;j++)
{
for(i=1;i<5;i++)
{
if (i==p) // to print the rows in that particular column
{a[j][i]=i;
printf(“%d”, a[j][i]);
}
}
printf(“\n”);
}
}