Thread: 2D array

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    10

    2D array

    Hi everyone,

    I want to create a two dimensional array whose size is 54*54.But I want to insert all the elements in program itself.How i do that.

    eg:array elements(54*54)

    Code:
    value weight[no_vertices] [no_vertices] =
    {
       {  5, 10 , 12, 45, 23, .........................}
       {45,  20, 11, 43, 60, ..........................}
       {20 ......................................................}
       {22, ....................................................}
       {...........................................................}
    
    };
    the problem is page is not enough.
    i want to insert all the elements in the program, any method to do that.
    thanks in advanced.(above is the example that i want to insert)

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by prdeepss View Post
    Hi everyone,

    I want to create a two dimensional array whose size is 54*54.But I want to insert all the elements in program itself.How i do that.

    eg:array elements(54*54)

    Code:
    value weight[no_vertices] [no_vertices] =
    {
       {  5, 10 , 12, 45, 23, .........................}
       {45,  20, 11, 43, 60, ..........................}
       {20 ......................................................}
       {22, ....................................................}
       {...........................................................}
    
    };
    the problem is page is not enough.
    i want to insert all the elements in the program, any method to do that.
    thanks in advanced.(above is the example that i want to insert)
    Leave off the space after the comma. The compiler doesn't need it. Ignore the width of the page, and don't hit enter, either.

    You'll need a comma at the end of every row's curly brace.

  3. #3
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Isn't the Statement for creating multidimensional arrays in C# <type> <arrayName>[index1,index2,index n]; ? or does the C way also work?
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Good catch WDT!

    I thought "value" was a name for a struct.

    You need something like this for an array of integers:

    Code:
    i/all your int's, with each row surrounded by curly braces, 
    and after each rows curly brace, add a comma (not a semi-colon, a comma), except on the last row. Put a semi-colon after the last curly brace, like so:
    
    ArrayName[54][54] = { 
    {1,2,3},
    {4,5,6},
    {7,8,9} };
    270 integers seems like a *lot* of integers to add by hand. I'd still suggest a file with the data, and have your program read the data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. Help with mallocing a 2d array please?
    By Gatt9 in forum C Programming
    Replies: 5
    Last Post: 10-10-2008, 03:45 AM
  3. 2D array pointer?
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 04-23-2006, 08:16 AM
  4. Read file in 2D array
    By Chook in forum C Programming
    Replies: 1
    Last Post: 05-08-2005, 12:39 PM
  5. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM