Skip to content

Instantly share code, notes, and snippets.

@ruyut
Created March 27, 2019 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruyut/24e323fec69619e73c83bbde86e1f1c8 to your computer and use it in GitHub Desktop.
Save ruyut/24e323fec69619e73c83bbde86e1f1c8 to your computer and use it in GitHub Desktop.
//801-3
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, j;
for (i = 1; i <= 5; i++) {//從1開始,一直到5 共會出現1,2,3,4,5
for (j = 0; j<5 - i; j++)printf(" ");//從(6-i)開始,一直到1
for (j = 0; j<i; j++)printf("*");//列印出*號
printf("\n");//換行
}
system("PAUSE");//停住等待使用者按下任意一個按鍵
return 0;//跳出
}
/*
第9行
for (j = 0; j<5 - i; j++)
i=1 , 5-1=4 , 4 3 2 1 列印出4個全形空白
i=2 , 5-2=3 , 3 2 1 列印出3個全形空白
i=3 , 5-3=2 , 2 1 列印出2個全形空白
i=4 , 5-4=1 , 1 列印出1個全形空白
i=5 , 5-5=0 , 列印出0個全形空白
第10行
for (j = 0; j<i; j++)printf("*");
i=1 , j= 0 列印出1個*
i=2 , j= 0 1 列印出2個*
i=3 , j= 0 1 2 列印出3個*
i=4 , j= 0 1 2 3 列印出4個*
i=5 , j= 0 1 2 3 4 列印出5個*
因為前面已經有空白,所以*號會在空白後面出現
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment