Thread: Two-dimensional array

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    7

    Two-dimensional array

    I really need help with this problem. I am not even sure where to start. Thank you in advance



    • Write a C program that uses a 2-dimensional (2D) array.
    • Use the word “array” as the array identifier
    • Define the size of the array as 10x10
    • Use for loop(s) to assign the following values to each of the array elements.



    Two-dimensional array-capture-png





    • Use for loop(s) to print the array in a nicely aligned table, as shown in picture above.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    We cannot and will not do your homework for you. Your instructor should have given you enough information you need in order to complete the assignment.

    Please see the Homework Guidelines for the site.

    One you have a first cut of the code, and present it here in Code Tags, then feel free to ask us specific questions.

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    I was not asking for you to do it for me. Just some assistance to point me in the right direction

  4. #4
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    This is what I have so far. As i have stated before I do not want you to do it for me just some help.
    Code:
    #include<stdio.h>
    
    
    int main()
    {
    	int a[10][10], i , j, r, c;
    
    
    	for (i = 0; i < 9; i++) 
    	{
    		for (j = 0; j < 9; j++)
    		
    	}
    
    
    	for (r = 0; r < 9; r++)
    	{
    		for ( c = 0; c < 9; c++)
    		{
    			printf("\n[%d]", a[i][j]);
    		}
    	}
    	return 0;
    }

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by Justin Time View Post
    This is what I have so far. As i have stated before I do not want you to do it for me just some help.
    Code:
    #include<stdio.h>
    
    
    int main()
    {
    	int a[10][10], i , j, r, c;
    
    
    	for (i = 0; i < 9; i++) 
    	{
    		for (j = 0; j < 9; j++)
    		
    	}
    
    
    	for (r = 0; r < 9; r++)
    	{
    		for ( c = 0; c < 9; c++)
    		{
    			printf("\n[%d]", a[i][j]);
    		}
    	}
    	return 0;
    }
    What is your output?

    What do you think the problem is?

  6. #6
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    Quote Originally Posted by rstanley View Post
    What is your output?

    What do you think the problem is?
    I did forget the equation for the first for loop to assign the variables. Here is what I have.

    Code:
    #include<stdio.h>
    
    
    int main(void)
    {
    	int a[10][10], i , j, r, c;
    
    
    	for (i = 0; i <= 9; i++) 
    	{
    		for (j = 0; j <= 9; j++)
    		a[i][j] = i;
    	}
    
    
    	for (r = 0; r < 9; r++)
    	{
    		for ( c = 0; c < 9; c++)
    		{
    			printf("\n[%d]", a[i][j]);
    		}
    	}
    	return 0;
    }

  7. #7
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    Here is the output I am getting
    Code:
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]
    [3544272]

  8. #8
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    I see where it went wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assigning One dimensional array to two dimensional array
    By lightning_star in forum C Programming
    Replies: 1
    Last Post: 03-19-2014, 09:44 PM
  2. Replies: 12
    Last Post: 09-02-2013, 07:50 PM
  3. Replies: 4
    Last Post: 09-02-2013, 11:19 AM
  4. Replies: 24
    Last Post: 11-11-2008, 01:39 PM
  5. Replies: 1
    Last Post: 04-25-2006, 12:14 AM