输入size,level,使用/\_,打印正三角形
#include<stdio.h>
int main() {
int level, size;
printf("Enter level and size :");
scanf("%d%d", &level, &size);
int left, right,width = size * 2; //小三角形的宽度
for (int i = 0; i < level*size; i++) {
for (int j =level * size -1-i; j >= 0; j--) //输出每行前的空格
printf(" ");
left = 0; //行左边界(可省略)
right = 2 * i+1; //行右边界
for (int j = left; j <= right; j++) {
if (j%width == 0) //与左边界相比每隔width个打印"/"
printf("/");
else if ((right - j) % width == 0) //与右边界相比每隔width个打印""
printf("\");
else if ((i + 1) % size == 0) //每隔size行不打印空格,打印"_"
printf("_");
else //补上空格
printf(" ");
}
printf("
");
}
return 0;
}