開發平台(Platform): (Ex: Win10, Linux, ...)
win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
轉成正空心三角形
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
#include <stdio.h>
#include <stdlib.h>
int main(void){
int a,b,i,k,p,l,c,m;
// a, i, k =loop index
// b = not used
// p = rows to be drawn
// l = height of the triangle
// c = temp variable for width calculation
// m = width of the triangle
char w;//the star symbol
printf("輸入指定的字元"); scanf("%s",&w);// read symbol
printf("請輸入你要的高度"); scanf("%d",&l);//read height
c=l-3;
m=(c*2)+5;//calculate the width of the triangle
p=l;//rows to draw - I would move this to the second for loop below
for(i=2;i<=m;i++) printf("%c",w); // draw the bottom of triangle
printf("\n"); // finiish the bottom
for(i=2;i<=l;i++) { // draw one line at a time
for(a=2;a<=i;a++) printf(" "); // draw the leading blanks
if(i<l) printf("%c",w); // draw the star, except for the last line
for(k=3;k<=p;k++)printf(" "); //draw the inside of the triangle, left
left half
for(k=4;k<=p;k++)printf(" "); //draw the inside of the triangle, right
right half
printf("%c\n",w); // draw the star at the right side
p