"C Language and Programming" Project 1-32-(5) & (6): Output Small stars

Source: Internet
Author: User

Problem Description: 44158317

Output Small Stars (5)

1#include"stdafx.h"2 3 intMain ()4 {5     intx, X1;6scanf_s ("%d", &x);7X1 =x;8     9     //Output line 1th (special line)Ten      for(inti =0; I < X-1; i++) One     { Aprintf" "); -     } -printf"*"); theprintf"\ n"); -  -     //output 2nd to X-1 line -      for(inti =1; I < X-1; i++) +     { -         //Output I line 1th set of spaces +          for(inti =1; I < x1-1; i++) A         { atprintf" "); -         } -x1--; -  -         //Output I line 1th * -printf"*"); in  -         //Output I line 2nd set of spaces to          for(intj =1; J <=2*i-1; J + +) +         { -printf" "); the         } *          $         //Output I line 2nd *Panax Notoginsengprintf"*"); -  the         //line Break +printf"\ n"); A  the     } +  -     //Output line X (special line) $      for(inti =0; I <2*x-1; i++) $     { -printf"*"); -     } theprintf"\ n"); - Wuyi     return 0; the}

Results

Output Small Stars (6)

1 intMain ()2 {3     intx, x1, x2;4scanf_s ("%d", &x);5X1 =x;6x2 = x-1;7 8     //input isosceles triangle Upper half (with Midline)9      for(inti =1; I <= x; i++)Ten     { One         //Output I line space section A          for(inti =0; I < x1-1; i++) -         { -printf" "); the         } -x1--; -  -         //Output I line * Section +          for(intj =0; J <2*i-1; J + +) -         { +printf"*"); A         } at  -         //line Break -printf"\ n"); -     } -  -     //enter the lower half of the isosceles triangle in      for(inti =1; I <= X-1; i++) -     { to         //Output I line space section +          for(intj =0; J < I; J + +) -         { theprintf" "); *         } $ Panax Notoginseng         //Output I line * Section -          for(inti =0; I <2*X2-1; i++) the         { +printf"*"); A         } thex2--; +  -         //line Break $printf"\ n"); $     } -      -  the     return 0; -}

Results

Feelings:

Writing "pseudo-code" can increase the readability of code;

"C Language and Programming" Project 1-32-(5) & (6): Output Small stars

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.