Results 1 to 7 of 7

Thread: convert one dimansional array to two dimansional array

  1. #1
    Geek_Guest
    Guest

    convert one dimansional array to two dimansional array

    Question asked by visitor Ms.Supriya Ahire.

    Hello All,

    Plz send me solution for following question...
    program to convert one dimansional array to two dimansional array .

    Thanks & Regards,
    Ms.Supriya Ahire.


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    18

    Re: convert one dimansional array to two dimansional array

    two dimenation mean second dimention indicates some field which will vary depends on user ?

    do you guess what the user give the size of second dimention?


  3. #3
    Junior Member
    Join Date
    Jul 2007
    Answers
    21

    Re: convert one dimansional array to two dimansional array

    suppose we do the following c code

    int a[5],i;

    here i declared a is an one dimentional array . After compilation it is not possible to convert into two dimensional .


  4. #4
    Contributing Member
    Join Date
    Nov 2007
    Answers
    46

    Re: convert one dimansional array to two dimansional array

    if the single dimentional array has to 5 elements like
    int a[5], which stores elements in single row.
    but in two dimentional we have row and coloumn. now we change above in to two dimentional
    int a[5][];
    the declaration tells a is a variable of type integer which has 5 rows and 0 coloumns and now write your program in two dimentional.


  5. #5
    Junior Member
    Join Date
    Jul 2007
    Answers
    18

    Smile Re: convert one dimansional array to two dimansional array

    Quote Originally Posted by rahulvegi View Post
    if the single dimentional array has to 5 elements like
    int a[5], which stores elements in single row.
    but in two dimentional we have row and coloumn. now we change above in to two dimentional
    int a[5][];
    the declaration tells a is a variable of type integer which has 5 rows and 0 coloumns and now write your program in two dimentional.
    thnks...


  6. #6
    Contributing Member
    Join Date
    Dec 2007
    Answers
    46

    Re: convert one dimansional array to two dimansional array

    Quote Originally Posted by Geek_Guest View Post
    Question asked by visitor Ms.Supriya Ahire.

    Hello All,

    Plz send me solution for following question...
    program to convert one dimansional array to two dimansional array .

    Thanks & Regards,
    Ms.Supriya Ahire.
    Supriya,

    You need to clarify this question better. Lets consider an example.
    1.
    int arr_of_colors[3] = {red, orange, black};
    This is a One-dimensional array.

    2.
    int favorite_color [person][favorite color];
    This is a two dimensional array: one dimension is the person, and second dimension is the favorite color.

    3.
    So, would it make sense to say "convert one dimensional array to a two dimensional array??" It does not to me. So, can you clarify your question??


  7. #7

    convert one dimansional array to two dimansional array

    Part i: statically allocated two dimensional arrays are defined using a syntax of type arrayname [rows][cols]; they are accessed in the same way as one-dimensional arrays: arrayname[r][c] accesses the value at row r, column c. Write a program that creates a two-dimensional array of integers with 5 rows and 3 columns, initializes each value to 0, and then writes out the array, row by row, one row per line. Passing multidimensional arrays is a little bit harder than passing one-dimensional arrays. Here is a sample header: const int numcolumns=15; // possibly more code here... Void foo(int my2darray[][numcolumns]) // notice we must tell how // many columns in the array // but must not how many rows... { // the code } main() { int myarray[5][numcolumns]; foo(myarray); } modify your previous program to pass its array to an initialize function that initializes the array, and to a print function that outputs the array. Handin problem 1: as with one-dimensional arrays, it is annoying to require different syntax for declaring and passing the arrays. Modify your array.h and array.c solutions (from cs 180) to work for a two-dimensional array (e.g. Create an array2d class). You will need constants for maxrows, maxcolumns, and class variables for numrows, numcoluns (as opposed to just length). Test your program by modifying the previous program to work with your new class. Now u happy . Why u waste time in sending mails , go to google search man .... Bye.. Have a nice day


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact