Write algorithms step by step ("counting stars ")

Source: Internet
Author: User

 

[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]

 

 

 

All the friends who have learned programming know that, in order to learn various syntax structures in programming languages, we should try to solve various strange questions. Among them, "counting stars" seems to be one of them. What is "Counting Stars? Is to print various shapes of "*", positive triangle, inverted triangle, diamond and so on. This blog is purely designed to commemorate our past years.

 

A) Positive triangle

 

 

Void star_1 ()

{

Int outer;

Int inner;

 

For (outer = 1; outer <10; outer ++ ){

For (inner = 1; inner <= outer; inner ++ ){

Printf ("% c ",'*');

}

Printf ("\ n ");

}

}

Void star_1 ()

{

Int outer;

Int inner;

 

For (outer = 1; outer <10; outer ++ ){

For (inner = 1; inner <= outer; inner ++ ){

Printf ("% c ",'*');

}

Printf ("\ n ");

}

} B) inverted triangle

 

 

Void star_2 ()

{

Int outer;

Int inner;

For (outer = 9; outer> = 1; outer --){

For (inner = 1; inner <= outer; inner ++ ){

Printf ("% c ",'*');

}

Printf ("\ n ");

}

}

Void star_2 ()

{

Int outer;

Int inner;

For (outer = 9; outer> = 1; outer --){

For (inner = 1; inner <= outer; inner ++ ){

Printf ("% c ",'*');

}

Printf ("\ n ");

}

} C) in the Left triangle, there are two rows between two rows.

 

 

 

Void star_3 ()

{

Int outer;

Int inner;

For (outer =-4; outer <= 4; outer ++ ){

For (inner = 1; inner <= (5-abs (outer); inner ++ ){

Printf ("*");

}

 

For (; inner <= 5; inner ++ ){

Printf ("");

}

 

Printf ("\ n ");

}

}

Void star_3 ()

{

Int outer;

Int inner;

For (outer =-4; outer <= 4; outer ++ ){

For (inner = 1; inner <= (5-abs (outer); inner ++ ){

Printf ("*");

}

 

For (; inner <= 5; inner ++ ){

Printf ("");

}

 

Printf ("\ n ");

}

} D) Right Triangle

 

 

Void star_4 ()

{

Int outer;

Int inner;

For (outer =-4; outer <= 4; outer ++ ){

For (inner = 1; inner <= abs (outer); inner ++ ){

Printf ("");

}

For (; inner <= 5; inner ++ ){

Printf ("*");

}

Printf ("\ n ");

}

}

Void star_4 ()

{

Int outer;

Int inner;

For (outer =-4; outer <= 4; outer ++ ){

For (inner = 1; inner <= abs (outer); inner ++ ){

Printf ("");

}

For (; inner <= 5; inner ++ ){

Printf ("*");

}

Printf ("\ n ");

}

} E) Vertical Diamond

 

 

Void star_5 ()

{

Int outer;

Int inner;

For (outer =-4; outer <= 4; outer ++ ){

For (inner =-4; inner <= abs (outer)-5; inner ++ ){

Printf ("");

}

For (; inner <= 5-abs (outer); inner ++ ){

Printf ("*");

}

Printf ("\ n ");

}

}

Void star_5 ()

{

Int outer;

Int inner;

For (outer =-4; outer <= 4; outer ++ ){

For (inner =-4; inner <= abs (outer)-5; inner ++ ){

Printf ("");

}

For (; inner <= 5-abs (outer); inner ++ ){

Printf ("*");

}

Printf ("\ n ");

}

} F) Horizontal Diamond

 

 

Void star_6 ()

{

Int outer;

Int inner;

For (outer =-9; outer <= 0; outer ++ ){

For (inner = outer; inner <0; inner ++ ){

Printf ("");

}

For (; inner <= 9; inner ++ ){

Printf ("*");

}

Printf ("\ n ");

}

}

Void star_6 ()

{

Int outer;

Int inner;

For (outer =-9; outer <= 0; outer ++ ){

For (inner = outer; inner <0; inner ++ ){

Printf ("");

}

For (; inner <= 9; inner ++ ){

Printf ("*");

}

Printf ("\ n ");

}

}

 

G) Yang Hui triangle

 

 

Void star_7 ()

{

Int outer;

Int inner;

For (outer = 1; outer <10; outer ++ ){

For (inner = 1; inner <= outer; inner ++ ){

Printf ("% 3d", outer * inner );

}

Printf ("\ n ");

}

}

Void star_7 ()

{

Int outer;

Int inner;

For (outer = 1; outer <10; outer ++ ){

For (inner = 1; inner <= outer; inner ++ ){

Printf ("% 3d", outer * inner );

}

Printf ("\ n ");

}

}

Related Article

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.