Hey, I am trying to print a 2D (3x3) array like this:
I tried a while loop but it didnt work of course, could someone help be make it print like the above?
Code:
#include <stdio.h>
#define NUM_ELEMENTS 3
int main()
{
int x[NUM_ELEMENTS][NUM_ELEMENTS]; //Declaration of the array
//int y[NUM_ELEMENTS][NUM_ELEMENTS];
//int z[NUM_ELEMENTS];
for(int a=0; a<NUM_ELEMENTS; a++)
{
for(int b=0; b<NUM_ELEMENTS; b++)
{
printf("Enter row %d and column %d: \n",a,b);
scanf("%d",&x[a][b]);
}
}
printf("\n"); //Space
//int loop=0;
for(int i=0; i<NUM_ELEMENTS; i++)
{
for(int j=0; j<NUM_ELEMENTS; j++)
{
//while(loop != 3)
//{
printf(" %d ",x[i][j]); //Printing of array contents
//loop++;
//}
}
}
}
Right now it prints like this:
Thanks