C语言实验——for循环打印图形(循环结构)

C语言实验——for循环打印图形(循环结构)

#include <stdio.h>
int main()
{
    int n, i ,temp;
    n=4;
    for(i=1;i<=n;i++)
    {
        for(temp = i; temp < n; temp++)
        {
            printf(" ");
        }
        for(temp = i; temp > 0; temp--)
        {
            printf("*");
        }
        for(temp = i - 1; temp >0; temp--)
        {
            printf("*");
        }
        printf("\n");
    }
    for(i = n - 1; i > 0; i--)
    {
        for(temp = i; temp < n; temp++)
        {
            printf(" ");
        }
        for(temp = i; temp > 0; temp--)
        {
            printf("*");
        }
        for(temp = i - 1; temp > 0; temp--)
        {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

相关文章:

  • 2021-12-21
  • 2021-12-28
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案