A19 Answer


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

/* Puzzle A19 -- print wedge of stars, n stars in the first row
|
|  Print n characters per row, however row k starts with k
|  spaces, with the remaining characters stars.
*/
int main(int argc, char *argv[])
{
  int row, col;
  int n=15 ;
  
  for ( row=0; row < n; row++ )
  {
    for ( col=0; col < row; col++ )
      printf(" ");
    for ( ; col < n; col++ )
      printf("*");
    printf("\n");
  }
  
  system("PAUSE");	
  return 0;
}

Comments: Notice the trick in the second nested for loop. The value in the variable col is left over from the first nested for loop. So the second for loop continues from where the first left off.

Tricky, tricky, tricky.... But this is common. You need to know what for loops do when the initializer is missing. Sounds like a great time to read your textbook!