[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 ");
}
}