/*=========================================
* Copyright (c) 2020, 逐风墨客
* All rights reserved.
*
* 文件名称:study_triangle.c
* 运行环境:Linux操作系统
* 功能描述:用for循环打印各种三角形
=========================================*/
#include <stdio.h>
#define VAL 6
int main(void)
{
int i, j, k;
printf("\n直角三角形:\n\n");
for (i=1; i<=VAL; i++)
{
for (j=1; j<=i; j++)
{
printf("*");
}
printf("\n");
}
printf("\n倒直角三角形:\n\n");
for (i=VAL; i>=1; i--)
{
for (j=1; j<=i; j++)
{
printf("*");
}
printf("\n");
}
printf("\n三角形:\n\n");
for (i=1; i<=VAL; i++)
{
for (j=VAL; j>=i; j--)
{
printf(" ");
}
for (k=1; k<=i+j; k++)
{
printf("*");
}
printf("\n");
}
printf("\n倒三角形:\n\n");
for (i=VAL; i>=1; i--)
{
for (j=VAL; j>=i; j--)
{
printf(" ");
}
for (k=i+j; k>=1; k--)
{
printf("*");
}
printf("\n");
}
return 0;
}
程序运行结果: