Two dimensional array

Hello readers,

I want to make an two-dimensional array, but it's not working.
If I compile my program it puts out an one dimensional array.... how?
Here is my code so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>



int main()
{
    int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
    int col;
    int row;
    
    for(row=0; row<3; row++){
               for(col=0; col<4; col++){
                          printf("%d",a[row][col]);
                          }
                          }

    getchar();
}

    

output:
12345678910


help please,
Dutchman
You have a 2D array.

It is printing as 1D because you are not putting any line breaks between the rows. All you have to do to fix is print a newline after each row.
Last edited on
I thought the array would do that automatically...
But thanks I have it now.
Topic archived. No new replies allowed.