Puzzle L20


Print a triange of stars, one star in the first row, three on the second . . . for 12 rows

[M-12]Write a main() program that prints a triangle of stars. Print 1 star in row 0, 3 stars in row 1, 5 stars in row 2, and so on. Here is what this looks like:

...........*...........
..........***..........
.........*****.........
........*******........
.......*********.......
......***********......
.....*************.....
....***************....
...*****************...
..*******************..
.*********************.
***********************

For the non-star characters, use dot or space. Often when debugging programs like this it is useful to print dot instead of space so that it is easier to see what the program did.

Here is a skeleton:

#include <stdio.h>
#include <stdlib.h>

/* Puzzle L20 - print a triangle of stars, n rows tall */
int main()
{
  int row, j, spaces, stars;
  int n=12;
  
  for (   )
  {
    stars = 2*row+1;
    spaces =
    
    for (  )
      printf(".");
    for (  )
      printf("*");
    for (   )
      printf(".");
    printf("\n");
  }
    
  printf("\n");
  	
  return 0;
}



Previous Page        Answer         Next Page         Home