two dimimension array...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mhrt2008
    New Member
    • May 2009
    • 6

    two dimimension array...

    hi all
    i want to initialize 2 dimension array in C and i need to print this array with the summation... any idea can help me with this code..

    Code:
    #include <stdio.h>
    void main()
    {
        int i,j;
        int table[i][j];
      table[2][2] = { { 1, 2},{ 4, 5} };
    
        printf("%d\t",table[2][2]);
                printf("\n");
    
    // sum 
        // 1+4    and   2+5
    
    }
  • unauthorized
    New Member
    • May 2009
    • 81

    #2
    Ok, first off, the code

    # int i,j;
    # int table[i][j];

    is wrong. You can't declare statically allocated arrays with variables as sizes, and even if you could - you still are using uninitialized variables. You can either use constants, or literal values.
    const int i=5, j=6; is what you should be using. Or #define for older C compilers.

    I suggest you read up on arrays, pointers and loops, because nobody wants to do your homework. There is a great tutorial about arrays in the answers section on this very forum. And there is always the whole Internet.

    When you are confident in your knowledge and have an actual question, feel free to ask. And try not to be so ambiguous.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Originally posted by unauthorized
      There is a great tutorial about arrays in the answers section on this very forum.
      You can find it here: Arrays Revealed

      Comment

      Working...