Print diamond in C Language

Source: Internet
Author: User

The description is omitted and the code is displayed directly.

Code:

1 # include "stdio. H "2 3/* output solid diamond */4 int output_1 (int A) 5 {6 int I, j, n, m; 7 printf ("The following are solid images \ n"); 8 m = A/2 + 1; 9 for (j = 1; j <= A; j ++) 10 {11 N = (m-j); 12 if (n <0) 13 N =-N; 14 for (I = 1; I <= A; I ++) 15 {16 if (I <= n | I> = 1 + a-n) 17 putchar (''); 18 else19 putchar ('*'); 20} 21 putchar ('\ n'); 22} 23 return 1; 24} 25 26/* output hollow diamond */27 int output_2 (int) 28 {29 int I, j, m, n; 30 m = A/2 + 1; 31 printf ("The following are hollow figures \ n "); 32 For (j = 1; j <= A; j ++) 33 {34 N = (m-j); 35 if (n <0) 36 n =-N; 37 For (I = 1; I <= A; I ++) 38 {39 if (I = n + 1 | I = A-N) 40 putchar ('*'); 41 else42 putchar (''); 43} 44 putchar ('\ n'); 45} 46 Return 1; 47} 48 49 int main () 50 {51 int N, choose; 52 while (1) 53 {54 printf ("enter an odd number. N = "); 55 scanf (" % d ", & N); 56 If (N % 2) 57 {58 printf (" select print diamond type: 1. solid; 2. hollow. \ nchoose = "); 59 scanf (" % d ", & choose); 60 if (choose = 1) output_1 (n); 61 else if (choose = 2) output_2 (n); 62 else printf ("error. \ n "); 63} 64} 65 66 return 0; 67}

 

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.