Thread: going to the next line

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    going to the next line

    I'm just learned about multi dimensional arrays in my class and my lab asks me to print each element using %10.4f. So i'm doing this and i try to start the next row and I can't. I've been stuck on this one part for about 30 minutes. Can someone please tell me how to do this.
    Last edited by psykid; 03-17-2010 at 04:58 AM. Reason: solved.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    array

    to navigate a 2d array i usually use 2 nested loops


    Code:
    for (down = 0; down < HEIGHT; down++)
    {
    
      for(across = 0; across < WIDTH; across++)
      {
           array[down][across] = whatever;
      }
    
    }

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    17

    You can print as follows

    Code:
    int main(void)
    {
    	int a[3][3]={1,2,3,4,5,6,7,7,8};
    	int i,j;
    	for(i=0;i<3;i++)
    	{
    	 for(j=0;j<3;j++)
    	 {
    	   printf("%d\t", a[i][j]);
    	 }
    	 printf("\n");
    	}
         return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 11:01 AM
  2. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-18-2009, 11:44 PM
  3. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  4. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  5. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM