Thread: newbie homework help please

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    newbie homework help please

    I have an assignment due tomorrow for a intro to c class that i am almost done with. This may be a dumb question, but how do you print a space? all by itself? I can left and right justify, but it isnt working for me here. I am kinda lost and its due tomorrow first thing. Any help would be appreciated. It is supposed to be an asterisk printing exercise to look like this:

    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

    *
    **
    ***
    ****
    and so on up to ten, which i have figured out, but the next part is to reverse this and have the spaces first, such as :

    ***********
    _**********
    __**********
    ___*********

    and so on. Here is what i have so far,
    Code:
    #include <stdio.h>
    int main()
    {
    
      int r=0;
      int c=0;
    
    
      /*pyramid top*/
    
      for ( r= 0; r <10; r++)
        {
          for (c=0; c<=r; c++)
            {
              printf("*");
            }
          printf("\n");
        }
      printf("\n");
    
    
      /*pyramid bottom*/
    
      for ( r= 0; r <10; r++)
        {
          for (c=10; c>r; c--)
            {
              printf("*");
            }
          printf("\n");
        }
      printf("\n");
    
    
      /*reverse top*/
    
      for ( r= 0; r <10; r++)
        {
          for (c=10; c>r; c--)
            {
              printf(" ");
            }
        }
      /*reverse bottom*/
    
    
      for ( r= 0; r <10; r++)
        {
          for (c=0; c<=r; c++)
            {
              printf("*");
            }
          printf("\n");
        }
      printf("\n");
    
    
      return 0;
    }
    thanks for any help or advice

  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
    Code:
      for ( r= 0; r <10; r++)
        {
          for (c=10; c>r; c--)
            {
              printf("!");  /*!! Watch */
            }
        }
    Result
    Code:
    $ ./a.exe
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    
    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
    
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    You printed ALL your spaces at once, not a few at a time on each line.
    Put the space printing loop inside the next loop
    loop
    - print some space
    - print some stars
    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
    Registered User
    Join Date
    Sep 2006
    Posts
    41
    you want to print the spaces like you are printing the stars.

    L /* number of lines */
    A /* number of astericks */
    S /* number of spaces */

    also, you don't need r=0. That is already defined in your for loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Newbie: Homework Help
    By soheel in forum C++ Programming
    Replies: 6
    Last Post: 10-04-2005, 10:59 AM
  3. Urgent homework help for NEWBIE
    By Kazasan in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2004, 04:23 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM