programs that print a pattern of adjacnet asterisks

program to print a pattern of adjacent asterisks

Page 1 of 1

6 Replies - 9087 Views - Last Post: 14 October 2012 - 04:30 AM Rate Topic: -----

#1 biddy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 26-January 07

programs that print a pattern of adjacnet asterisks

Posted 26 January 2007 - 11:32 AM

Hi all

I am trying to write a program that prints the following patterns seperatley one below each other. I have to use the For loop and all asterisks should be printed with a single printf statement of the form printf (*).
A. B
* **********
** *********
*** ********
**** *******
***** ******
****** *****
******* ****
******** ***
********* **
********** *


I am just learning C, can anyone help? Please see below for first attempt....

#include <stdio.h>
int main (void)

int x ; /*counter*/

for ( x=0 ; x<=0 ; x+=1 )

if ( x ==1 ) {
printf ( '*\n' , x) ;

How do I repeat the if when x = =2 without having my printf as printf ('**'\n)

Is This A Good Question/Topic? 0
  • +

Replies To: programs that print a pattern of adjacnet asterisks

#2 Ellie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 8
  • View blog
  • Posts: 533
  • Joined: 17-January 07

Re: programs that print a pattern of adjacnet asterisks

Posted 26 January 2007 - 01:01 PM

View Postbiddy, on 26 Jan, 2007 - 06:32 PM, said:

Hi all

I am trying to write a program that prints the following patterns seperatley one below each other. I have to use the For loop and all asterisks should be printed with a single printf statement of the form printf (*).
A. B
* **********
** *********
*** ********
**** *******
***** ******
****** *****
******* ****
******** ***
********* **
********** *


I am just learning C, can anyone help? Please see below for first attempt....

#include <stdio.h>
int main (void)

int x ; /*counter*/

for ( x=0 ; x<=0 ; x+=1 )

if ( x ==1 ) {
printf ( '*\n' , x) ;

How do I repeat the if when x = =2 without having my printf as printf ('**'\n)


Can you use nested for loops? I think the easiest way to do this is with one outer loop and 2 inner loops, with both the inner loops containing your printf("*"); statement.
Was This Post Helpful? 0
  • +
  • -

#3 dedman  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 22-April 05

Re: programs that print a pattern of adjacnet asterisks

Posted 26 January 2007 - 02:05 PM

I may be wrong, but your For loop is only going to do 1 iteration. After the first time through it will add 1 to x and then x<=0 becomes false and the loop terminates.

I know it doesn't completely solve your problem, but it is a start and I don't want to get in trouble ("working" right now).
Was This Post Helpful? 0
  • +
  • -

#4 biddy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 26-January 07

Re: programs that print a pattern of adjacnet asterisks

Posted 26 January 2007 - 02:53 PM

Yeah, you're right. Have just tired a nested for loop and it worked perfectly...... thanks!
Was This Post Helpful? 0
  • +
  • -

#5 Ellie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 8
  • View blog
  • Posts: 533
  • Joined: 17-January 07

Re: programs that print a pattern of adjacnet asterisks

Posted 26 January 2007 - 03:03 PM

View Postbiddy, on 26 Jan, 2007 - 09:53 PM, said:

Yeah, you're right. Have just tired a nested for loop and it worked perfectly...... thanks!


Fantastic :D
Was This Post Helpful? 0
  • +
  • -

#6 knavekiller  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 31-July 12

Re: programs that print a pattern of adjacnet asterisks

Posted 14 October 2012 - 03:20 AM

try two nested for loops n im sure ur gonna get ur ans
Was This Post Helpful? -1
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: programs that print a pattern of adjacnet asterisks

Posted 14 October 2012 - 04:30 AM

One thinks that they might have found the answer to their question in the intervening FIVE YEARS.

Please pay attention to the age of the topic to which you're responding, and don't resurrect really old topics.

Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1