Hi this programm is interesting and tough..

This is a discussion on Hi this programm is interesting and tough.. within the C Programming forums, part of the General Programming Boards category; Hi. I need alil help with this question. This question is taken from the book ( C How to program ...

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

    Wink Hi this programm is interesting and tough..

    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) B) C)
    * ********** **********
    ** ********* *********
    *** ******** ********
    **** ******* *******
    ***** ****** ******
    ****** ***** *****
    ******* **** ****
    ******** *** ***
    ********* ** **
    ********** * *

    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
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    First off, post your code. We'll help from there. This is a farily easy problem.

    left, center, right

    center always stays the same
    left increments once each loop untill it reaches the far right side
    right decrements once each loop until it reaches position 0
    Pesudocode.
    Code:
    do
    {
        for( x = 0; x < width; x++ )
            if( left != right )
                if( x != left ) print a *
                else print a space
                if( x != right ) print a *
                else print a 
            if( x == center ) print a space
        left++, right++
    while( left != width -1 );
    I'll leave the rest to you.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Here's a skeleton that pretty much does half the work. I don't want to give the answer because... well, this really is something you need to understand.
    Code:
    #include <stdio.h>
    
    int main (void) {
      int i, j;
      for (i = 1; i < 8; i++) 
      {
        // Maybe you'll need another for loop here for some of the problems?
        for (j = 0; j < 8; j++)  // The parameters of the for loop will have to change
        {       
          printf ("*");
        }
        printf ("\n");
      }
      return 0;
    }
    Callou collei we'll code the way
    Of prime numbers and pings!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Using code tags on this board will help keep the layout of what you are typing.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Oh how dissapointing. I thought that was supposed to be all one pattern. Now I find out it's just something extremely simple. Sigh...

    I was hoping they wanted something fun like:
    Code:
    #include <stdio.h>
    int main ( void )
    {
    	int w=21,l=0,r=w-1,c=w/2,x;
    	do
    	{
    		for( x = 0; x < w; x++ )
    		{
    			if( l != r )
    			{
    				if( x == l  || x == r || x == c )
    					printf(" ");
    				else
    					printf("*");
    
    			}
    			else
    				printf(" ");
    		}
    		l++;
    		r--;
    		printf("\n");
    	}
    	while( l != w-1 );
    	return 0;
    }
    Quzah.
    Last edited by quzah; 06-27-2002 at 08:00 PM.
    Hope is the first step on the road to disappointment.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I was hoping they wanted something fun
    You should know better than to get your hopes up, we don't get that lucky.

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

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21