算法竞赛入门经典习题2-4 倒三角形

题目分析;

  1、假设计数变量 i 从0开始;

  2、第 i 行输出 i 个空格;

  3、每行输出 (n-i)*2-1 个*;

  4、注意换行

 1 #include <stdio.h>
 2 
 3 int main(int argc, const char * argv[]) {
 4     int i,j,n,temp;
 5     while(scanf("%d",&n)!=EOF)
 6     {
 7         for(i=0;i<n;i++)
 8         {
 9             for(j=0;j<i;j++)
10             {
11                 printf(" ");
12             }
13             temp=2*(n-i)-1;
14             for(j=0;j<temp;j++)
15             {
16                 printf("*");
17             }
18             printf("
");
19         }
20     }
21 }
View Code
原文地址:https://www.cnblogs.com/kongkaikai/p/4679634.html