#include <stdio.h> #include <stdlib.h> /* Puzzle A17 -- 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 argc, char *argv[]) { int line, col; int n=15 ; for ( line=0; line < n; line++ ) { for ( col=0; col < line; col++ ) printf("."); printf("*\n"); } printf("\n"); system("PAUSE"); return 0; }
Comments: It is, perhaps, a "trick", that the star is printed outside of the inner loop. But, how else could you do it?