Thread: sorry i had to post it again (Need a lil help)

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    sorry i had to post it again (Need a lil help)

    Hi. I need alil help with this question.

    This question is taken from the book ( C How to program 3/e by Deitel & Deitel) from the chapter 4 , question 4.16.

    4.16 Write a program that prints the following patterns separately one below the other. Use for loops to generate the patterns.All asterisks (*) should be printed by a single printf statement of the form printf ( “*” ); (this cases the asterisks to print side by side).Hint: The last two patterns require that each line begin with an appropriate number of blanks.

    A)
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********

    I know its a very odd but a good question i have been trying but dint even move a step further...

    Thanks alot

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Well, you could do it the fun way:
    Code:
    x=6,_x=7,x_=7;main_(x,_x)
    {return(x>0?x_--,main_(x-
    printf("%c",_x),_x):x_);}
    main(){x>0?main_(main_(x,
    32),42),x_+=_x+=1,printf
    ("%c",'\n'),--x,main():0;}
    Or the boring way:
    Code:
    int main ( void )
    {
      int lines, i, spaces, fills = 1;
      printf ( "Enter the number of lines to print: " );
      scanf ( "%d", &lines );
      for ( spaces = lines; spaces > 0; spaces--, fills+=2 ) {
        for ( i = 0; i < spaces; i++ ) putchar ( ' ' );
        for ( i = 0; i < fills;  i++ ) putchar ( '*' );
        for ( i = 0; i < spaces; i++ ) putchar ( ' ' );
        putchar ( '\n' );
      }
      return 0;
    }
    >I know its a very odd but a good question
    I'm sure it was good the first time it was asked. But this is a standard homework question, so we see it a lot. On the plus side, I've come up with a great many ways to do it over the years.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help (Trying to post message)
    By mrkm in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-06-2003, 04:05 PM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM
  4. post update
    By iain in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-12-2001, 10:47 AM