(C syntax FAQ 38)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.