找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 322|回复: 4

输出指定图形

[复制链接]

205

主题

173

回帖

6925

积分

论坛元老

积分
6925
发表于 2013-6-15 23:30:03 | 显示全部楼层 |阅读模式
输出如下图形:
2013年4月27号第二题:
[attachment=202]

[attachment=201]

205

主题

173

回帖

6925

积分

论坛元老

积分
6925
 楼主| 发表于 2013-6-15 23:30:52 | 显示全部楼层
参考答案:

/**************************************************************
*     Copyright (C) 2006-2013 All rights reserved.
*       @Version: 1.0
*       @Created: 2013-05-01 21:09
*        @Author: guozi - qin@126.com
*   @Description:
*
*       @History:
**************************************************************/
#include <stdio.h>
#define MAX_COL 2*100 - 1  //max column
#define MAX_ROW MAX_COL

/**
* @brief output
*
* @Param: N
*/
void output(int N)
{
    int a[MAX_COL][MAX_ROW] = {0};
    int col,row,i;

    if( 2*N - 1 > MAX_COL )
    {
        printf("lease input a number between[1-199]\n");
        return ;
    }
    /*Initialize array a*/
    for(i=0; i<N; i++)
    {
        for(col = i,row = i; col < 2*N - 1 - i; col++)
            a[row][col] = i + 1;

        for(row= i,col = i; row < 2*N - 1 - i; row++)
            a[row][col] = i + 1;

        for(col=i,row=2*N-2-i; col < 2*N - 1 - i; col++)
            a[row][col] = i+1;

        for(row=i,col=2*N-2-i; row < 2*N - 1 - i; row++)
            a[row][col] = i+1;

    }
    /*output array*/
    for(row=0; row<2*N-1;row++)
    {
        for(col=0; col<2*N-1;col++)
            printf("%2d ",a[row][col]);
        printf("\n");
    }

}

int main()
{
    int N;

    printf("lease input a number:");
    scanf("%d",&N);
    output(N);

    return 0;
}

14

主题

65

回帖

0

积分

新手上路

积分
0
发表于 2013-6-17 19:54:16 | 显示全部楼层
我也来做一下。

205

主题

173

回帖

6925

积分

论坛元老

积分
6925
 楼主| 发表于 2013-6-17 22:35:52 | 显示全部楼层
精妙

205

主题

173

回帖

6925

积分

论坛元老

积分
6925
 楼主| 发表于 2013-6-17 22:37:09 | 显示全部楼层

回 boyfaceone 的帖子

boyfaceone:我也来做一下。&#160;(2013-06-17 19:54)&#160;
建议以后直接把代码贴出来,不要上传附件。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 21:05 , Processed in 0.082170 second(s), 21 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表