开发平台(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