Thread: loop question

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    Question loop question

    Hello,

    Can anyone help me fix this program?
    That's all i can do.

    Code:
    #include<stdio.h>
    
    #define ROW 9
    #define COL 11
    
    int main(void)
    {
         int i, j;
    
         for(i=1; i<=ROW; i++)
         {
              for(j=1; j<i+1; j++)  
                   printf("*");
                   printf("\n");
         }
            
         for(i=0; i<COL; i++)
              printf("*");
              printf("\n");
    
         for(i=1; i<=ROW; i++)
         {
              for(j=0; j<ROW-i; j++)        
                   printf("*");
                   printf("\n");
         }
         return 0;
    }
    
    
    OUTPUT
    ------
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    ***********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
    
    Press any key to continue
    
    /***********************************************/
    
    My CORRECT OUTPUT should look like this
    "-"=spaces
    
    
    -----*
    ----***
    ---*****
    --*******
    ***********
    --*******
    ---*****
    ----***
    -----*
    [edit]Code tags added by Hammer. Please use them next time.

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    i'm a bit confused. how do you expect to get spaces in your output if there isnt a printf (" ") anywhere in it?
    hello, internet!

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    A simple solution to this problem would be to initialize all the elements of an array of the appropriate size to 0. Then just assign the '*' to the necessary elements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For loop question
    By JuzMe in forum C++ Programming
    Replies: 11
    Last Post: 04-20-2009, 08:39 AM
  2. Loop question
    By kwood965 in forum C Programming
    Replies: 6
    Last Post: 10-29-2008, 11:12 PM
  3. simple for loop function question
    By felicityxiv in forum C Programming
    Replies: 7
    Last Post: 05-06-2006, 11:43 PM
  4. Please don't laugh...SIMPLE loop question!
    By the_lumin8or in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2006, 01:08 PM
  5. while loop question
    By rayrayj52 in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2004, 05:13 PM