[問題] 詢問C/C++程式方面的問題
開發平台(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--; // one more line has been drawn
}
system("pause"); // keep the window open
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.139.158.52
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1553623536.A.119.html
噓
03/27 02:11,
6年前
, 1F
03/27 02:11, 1F
推
03/27 08:22,
6年前
, 2F
03/27 08:22, 2F
推
03/27 12:18,
6年前
, 3F
03/27 12:18, 3F
噓
03/27 15:37,
6年前
, 4F
03/27 15:37, 4F
噓
03/27 18:56,
6年前
, 5F
03/27 18:56, 5F
→
03/27 20:24,
6年前
, 6F
03/27 20:24, 6F
推
03/27 21:39,
6年前
, 7F
03/27 21:39, 7F
→
03/27 21:39,
6年前
, 8F
03/27 21:39, 8F
→
03/27 23:51,
6年前
, 9F
03/27 23:51, 9F
→
03/28 13:44,
6年前
, 10F
03/28 13:44, 10F
→
03/28 14:01,
6年前
, 11F
03/28 14:01, 11F
→
03/28 14:02,
6年前
, 12F
03/28 14:02, 12F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):