Typesetting problem - trapezoid

Subject description:

  Enter a height h, the output of a height is h, h, on the base of the trapezoid

Sample input:

4

Sample output:

         ****

      ******

   ********

**********

#include<stdio.h>
int main()
{
    int h;
    while(scanf("%d",&h)!=EOF)
    {
        int max=h+(h-1)*2;
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=max;j++)
            {
                if(j<max-h-(i-1)*2+1)
                {
                    printf(" ");
                }
                else
                {
                    printf("*");
                }
            }
            printf("\n");
        }
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/womendouyiyang/p/11666820.html