Thread: Array

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    19

    Array

    Hi, I'm trying to create a two dimensional array that displays zeroes in a 10 by 10 format. But I don't really know how.
    I've been playing around and this is what I have so far:

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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Try
    printf("%d "
    inside the j loop

    and
    printf("\n") in the i loop
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Look up "Printf format specifications" for how to print a number using a certain field width
    Also, ask yourself, when do you need to print a newline?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Mar 2013
    Posts
    19
    So I got the 30*30 matrix.

    But it's just a block of zeroes. How can I make it more presentable?

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by eterna View Post
    But it's just a block of zeroes. How can I make it more presentable?
    Write a program that generates a powerpoint slideshow?

    How do you expect anyone to know what what you consider to be "presentable" unless you tell them. Mindreading?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    19
    Quote Originally Posted by grumpy View Post
    Write a program that generates a powerpoint slideshow?

    How do you expect anyone to know what what you consider to be "presentable" unless you tell them. Mindreading?
    presentable= anything that doesn't just look like like a block of zeroes, whilst maintaining the 30 columns by 30 rows structure

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Have you looked into the advice given in post #3? If that's not what you're looking for, then you'll have to be more specific.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 09-09-2012, 02:29 PM
  2. Replies: 2
    Last Post: 03-20-2012, 08:41 AM
  3. Replies: 9
    Last Post: 08-23-2010, 02:31 PM
  4. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  5. Replies: 1
    Last Post: 04-25-2006, 12:14 AM