#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Trouble with nested printf statement


    Does anyone know why this is outputting '4200192' as a single line instead of the contents of the matrix with newline after each element? Im using gcc compiler. Thanks in advance.


    #include<stdio.h>
    #include<stdlib.h>

    main()
    {
    int a[3][2] = {{1,2},{3,4},{5,6}};
    int i,j;

    for (i=0;i<3;i++);{
    for (j=0;j<2;j++);{
    printf("%d\n",a[i][j]);
    }
    }

    }
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    A for loop iterates over a single statement. That statement can be a {block}. That statement can be
    /* empty */;

    Remove the semi-colons between ) and {

    Code:
    for (initialization; test; change)  /* no semi-colon */ {
      statements;
    }
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo