Knowledge point:
Flexible Use of for and if statements.
Think about algorithms.
This question can be made using a two-dimensional array.
The advantage is a clever combination of * and $
Content:
Output graphics
***** $
* ** $
* $
The rule is... discover it by yourself.
Input 3 to output the above three rows
Input description:
The number of rows is less than 40
Output description:
Input example:
3
Output example:
***** $
* ** $
* $
Method 1:
# Include <stdio. h> int main () {int n, a, B, y = 1, x, I; scanf ("% d", & N); X = N; // pre-control the number of rows to facilitate future decline for (I = 0; I <n; I ++) // control the number of rows, line feed {for (a = 0; A <2 * X-1; A ++) // for output * {printf ("*");} for (B = 0; B <Y; B ++) // The first row has a $ {printf ("$");} y + = 2; // increments the row with Y + 2 $ X-= 1; // decrease the number of functions to control *, corresponding to "for output *" printf ("\ n"); If (n = 0) break; // when there is no row, terminate the for loop and the program ends} return 0 ;}
Method 2:
# Include <stdio. h> int main () {char a [100] [1000]; int I, n, m, Y; scanf ("% d", & N); y = N; for (I = 0; I <n; I ++) {for (m = 0; m <2 * Y-1; m ++) {A [I] [m] = '*'; printf ("% C", a [I] [m]) ;}for (; m <2 * N; M ++) // link the above M until 2 * n {A [I] [m] = '$'; printf ("% C ", A [I] [m]);} y-= 1; if (y = 0) break; printf ("\ n ");} printf ("\ n"); Return 0 ;}
(C syntax FAQ 38)