谭浩强C第四版(p141)16.输出以下图案

  • Post author:
  • Post category:其他


运行结果:

   *
  ***
 *****
*******
 *****
  ***
   *
Press any key to continue

#include<stdio.h>
int main()
{
    int i,j,k=3;
    for(i=1;i<=7;i++)
    {
        if(i<=4)
        {    k--;
            for(j=0;j<=k;j++)printf(" ");
            for(j=1;j<2*i;j++)printf("*");
            printf("\n");
        }
        else
        {   k++;
            for(j=0;j<=k;j++)printf(" ");
            for(j=1;j<(3-k)*2;j++)printf("*");
            printf("\n");                        
        }
    }
    return 0;
}

方式二:

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

转载于:https://www.cnblogs.com/happyfei/p/10809383.html