标题:打印菱形问题代码(可输入大小)
只看楼主
zglcx123
Rank: 2
等 级:论坛游民
帖 子:60
专家分:10
注 册:2007-7-2
 问题点数:0 回复次数:0 
打印菱形问题代码(可输入大小)
(vc++6.0编译通过):
#include<stdio.h>
int main(void)
{
    int i, j, number;

    printf("Input your number: ");
    scanf("%i", &number);

    for(i = 0; i < (2*number-1); ++i)
    {

        if( i < number -1)
        {
            for(j = 0; j < (2*number-1); ++j)
            {
                if( j == number-1 - i  || j == number-1 + i )
                    printf("*");
                else
                    printf(" ");
            }
            printf("\n");
        }
        else if( i == number -1)
        {
            for( j = 0; j < (2*number-1); ++j)
            {
                if( j == number-1-i  || j == number-1 +i )
                    printf("*");
                else
                    printf(" ");
            }
            printf("\n");
        }
        else
        {
            for( j = 0; j < (2*number-1); ++j)
            {
                if( ((i - number) == (j-1)) || ((i - number) == ( 2*number-3 - j)) )
                    printf("*");
                else
                    printf(" ");
            }
            printf("\n");
        }

    }

    return 0;
}
搜索更多相关主题的帖子: 菱形 打印 代码 输入 
2008-04-23 15:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-210655-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.275835 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved