| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 630 人关注过本帖
标题:打印菱形问题代码(可输入大小)
取消只看楼主 加入收藏
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
快速回复:打印菱形问题代码(可输入大小)
数据加载中...
 
   



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

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