Puzzle L17


Print a diagonal line of stars

[E-7]Write a main() program that prints n lines. On line j, print j dots, followed by a single *. For example, for n==15:

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

Things are starting to get a little bit tricky. Several things need to be coordinated in this program.

Hard code the value of n, or ask the user.

Here is a skeleton:

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

/* Puzzle L17 -- print a diagonal line of stars
|
|  Print one star per line. Line 0 has a star in col 0,
|  line one has a star in col 1, and so on for n lines.
*/
int main()
{
  int line, col;
  int n=15 ;
  
  for (   )
  {
    for (   )
      printf( );

    printf( );
  }
  
  printf("\n");
  
  return 0;
}


Previous Page        Answer         Next Page         Home