# C++算法之数星星

``````a）正三角
``````
```void star_1()
{
int outer;
int inner;

for(outer = 1; outer <10; outer ++){
for(inner = 1; inner <= outer; inner ++){
printf("%c ", '*');
}
printf("\n");
}
}

```
``````                                    b）倒三角
``````
```void star_2()
{
int outer;
int inner;

for(outer = 9; outer >= 1; outer --){
for(inner = 1; inner <= outer; inner ++){
printf("%c ", '*');
}
printf("\n");
}
}

```
``````                                  c）左三角﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿
``````
```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） 右三角
``````
```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）垂直菱形
``````
```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）水平菱形
``````
```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）杨辉三角形
``````
```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");
}
}

```

0人收藏

0

0

»更多 您可能感兴趣的代码
1. 2012-12-06 21:23:15c++大数阶乘算法 by zetaliang
2. 2012-12-20 13:30:20伪造硬币问题 by 傅小黑
3. 2013-07-27 15:09:08C++顺序表操作代码演示 by qqmmcc
4. 2014-04-05 14:40:50C++算法之可变参数 by 童学芬
5. 2014-05-18 11:40:55KMP字符串匹配算法 by 童学芬
6. 2014-05-19 15:46:15高效素数筛法 by lucasli
7. 2014-05-20 12:48:01线性表之顺序表 by 千万不要郁闷
8. 2014-05-22 13:29:39递归题改为非递归题实例 by lucasli
9. 2014-05-27 11:43:40广度优先遍历 by aiheng1988
10. 2014-06-04 11:01:43阶乘之和 by 小项
11. 2019-06-17 21:18:10PHP+jQuery.photoClip.js图片裁剪上传实例 by 素材火官网

1. leaver 发表 2013-06-02 07:44:22 阿里巴巴5月5日综合算法题详解
2. dianlujitao 发表 2014-10-16 14:11:10 CodeForces 23A You’re Given a String…
3. dianlujitao 发表 2014-10-17 13:14:36 CodeForces 23B Party
4. dianlujitao 发表 2014-10-17 13:32:08 POJ 2339 Rock, Scissors, Paper
5. bystander 发表 2013-04-11 10:50:25 模板栈以及中缀表达式求值(C++实现)
6. dianlujitao 发表 2014-10-17 13:42:33 POJ 3844 Divisible Subsequences
7. dianlujitao 发表 2014-10-17 13:45:25 POJ 3122 Pie
8. bystander 发表 2013-04-16 00:42:58 模板优先级队列及堆排序(C++实现)
9. dianlujitao 发表 2014-10-17 13:52:22 POJ 2388 Who’s in the Middle
10. surgesoft 发表 2014-10-28 08:01:58 LeetCode OJ: Restore IP Addresses
11. espace 发表 2015-07-18 17:43:14 Two Sum
12. abyssss 发表 2014-05-20 03:23:39 数据结构 最小堆 数组实现