/*=========================================
* Copyright (c) 2020, 逐風(fēng)墨客
* All rights reserved.
*
* 文件名稱:study_triangle.c
* 運(yùn)行環(huán)境:Linux操作系統(tǒng)
* 功能描述:用for循環(huán)打印各種三角形
=========================================*/
#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;
}
??程序運(yùn)行結(jié)果: