please help me. my program is working but not displaying the table but i followed the syntax for the two-dimensional array. how come the program does not display the table? here is the code. :D

#include<stdio.h>
#include<conio.h>

main()
{
      int x[5][5],a,j;
      for (a=0;a<=5;a++)
      for (j=0;j<5;j++)
      x[a][j]=(a*4)+j+1;
      
      for (a=0;a<=5;a++)
      for (j=0;j<5;j++)
      printf("%d\n",x[a][j]);
      getch();
      }

When a=5, you are trying to read and write x[5][0]. This is not your memory and your code segfaults.


Change for (a=0;a<=5;a++) to for (a=0;a<5;a++)

in both sets of loops.

When you ran your code, it should have crashed and you should have seen an error message indicating that there was a segFault.

http://ideone.com/sonvy

i have a question sir/ma'am. My professor wants that the output should be in a table and in a sequence. how can i do that? or that it is not possible?

Change

printf("%d\n",x[a][j]);

to

printf("%d ",x[a][j]);

and only printf the newline when the value of a changes.

i have a question sir/ma'am. My professor wants that the output should be in a table and in a sequence. how can i do that? or that it is not possible?

You mean like this :

for (a=0;a<5;a++){
    for (j=0;j<5;j++)
        printf("%d\t",x[a][j]);
    printf("\n");
}

YES! just like that. thanks a lot! :D thanks to the both of you. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.