2 jzx 606 jzx_606 于 2015.05.30 11:54 提问

问个图形打印的题目求指导

要打印个空心等腰梯形,输入n为3,麻烦看下我的程序哪里错了

图片说明

#include

int main(void){
int n,i,j;
printf("Input n: ");
scanf("%d",&n);
for (i=1;i<=n;i++){
if (i==1||i==n){
for (j=1;j<=n-i;j++)
printf(" ");
for(j=n-j+1;j<=n+i+1;j++)
printf("*");
printf("\n");}
else
for (j=1;j<=n-i;j++){
printf(" ");
if (j==i||j==3*i+1)
printf("*");
printf("\n");}
}}

4个回答

caozhy
caozhy   Ds   Rxr 2015.05.30 12:11
已采纳
Input n: 6
     *******
    *       *
   *         *
  *           *
 *             *
*****************
Press any key to continue 
caozhy
caozhy   Ds   Rxr 2015.05.30 12:11
 // app1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
int main(void)
{
    int n,i,j;
    printf("Input n: ");
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        for (j = 0; j < n - i; j++)
            printf(" ");
        if (i == 1 || i == n)
        {
            for (j = 0; j < n + i * 2 - 1; j++)
                printf("*");
        }
        else
        {
            printf("*");
            for (j = 1; j < n + i * 2 - 2; j++)
                printf(" ");
            printf("*");
        }
        printf("\n");
    }
}

caozhy
caozhy   Ds   Rxr 2015.05.30 12:12
// app1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
int main(void)
{
    int n,i,j;
    printf("Input n: ");
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        for (j = 0; j < n - i; j++)
            printf(" ");
        if (i == 1 || i == n)
        {
            for (j = 0; j < n + i * 2 - 2; j++)
                printf("*");
        }
        else
        {
            printf("*");
            for (j = 1; j < n + i * 2 - 3; j++)
                printf(" ");
            printf("*");
        }
        printf("\n");
    }
}

caozhy
caozhy   Ds   Rxr 2015.05.30 12:13
 Input n: 3
  ***
 *   *
*******
Press any key to continue


Input n: 10
         **********
        *          *
       *            *
      *              *
     *                *
    *                  *
   *                    *
  *                      *
 *                        *
****************************
Press any key to continue
Csdn user default icon
上传中...
上传图片
插入图片