Skip to content

Instantly share code, notes, and snippets.

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