| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 497 人关注过本帖
标题:数组问题
只看楼主 加入收藏
燕锋少龙
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-8-22
结帖率:50%
收藏
已结贴  问题点数:0 回复次数:3 
数组问题
# include <stdio.h>
# define A 8
# define B 12
# define C 0//C的赋值和D的赋值,决定于要算从C到D之间的数组数!例如C=0,和D=7就是算8组数组的列之和!
# define D 7
int main(void)
{
    int i, j ,total;
    int arry[A][B] = {
        {3,1,0,0,0,1,0,0,0,0,2,0},
        {0,0,0,0,1,1,0,0,0,3,1,1},//  2  2  0  1  3  1  3  2  1  5  3  5
        {0,0,0,0,0,0,3,0,0,1,1,2},
        {0,1,0,1,2,0,0,1,0,1,1,0},
        {2,1,0,0,0,0,0,1,1,0,0,2},
        {1,1,0,1,0,1,1,0,1,1,0,0},
        {1,0,0,1,0,1,1,1,1,0,0,1},
        {1,0,0,0,3,0,1,0,1,0,1,0}
    };
       for(j = 0; j < B; ++j)
    {
        total = 0;
        for(i = C; i <= D; ++i)
        {
            total += arry[i][j];                        
        }
        
        printf("%3d", total);
        
    }
    putchar('\n');
   
    return 0;
}
//输出结果:
  8  4  0  3  6  4  6  3  4  6  6  6!
这俨然是个数组!怎么把这结果赋给数组,就是组成新的数组!并且能输出和运算!
搜索更多相关主题的帖子: include total 
2011-10-15 20:18
nomify
Rank: 5Rank: 5
等 级:职业侠客
帖 子:79
专家分:366
注 册:2011-10-13
收藏
得分:5 
程序代码:
# include <stdio.h>
# define A 8
# define B 12
# define C 0//C的赋值和D的赋值,决定于要算从C到D之间的数组数!例如C=0,和D=7就是算8组数组的列之和!
# define D 7
int main(void)
{
    int i, j ,total,output[B];
    int arry[A][B] = {
        {3,1,0,0,0,1,0,0,0,0,2,0},
        {0,0,0,0,1,1,0,0,0,3,1,1},//  2  2  0  1  3  1  3  2  1  5  3  5
        {0,0,0,0,0,0,3,0,0,1,1,2},
        {0,1,0,1,2,0,0,1,0,1,1,0},
        {2,1,0,0,0,0,0,1,1,0,0,2},
        {1,1,0,1,0,1,1,0,1,1,0,0},
        {1,0,0,1,0,1,1,1,1,0,0,1},
        {1,0,0,0,3,0,1,0,1,0,1,0}
    };
    for(j = 0; j < B; ++j)
    {
        total = 0;
        for(i = C; i <= D; ++i)
        {
            total += arry[i][j];                       
        }
        output[j] = total;
//        printf("%3d", total);
       
    }
    for(i=0;i!=B;++i)
        printf("%d ",output[i]);
    putchar('\n');
   
    return 0;
}
2011-10-15 22:32
jcw08120110
Rank: 8Rank: 8
来 自:南京
等 级:蝙蝠侠
帖 子:272
专家分:742
注 册:2009-6-8
收藏
得分:0 
hh

君生我未生 我生君以老
2011-10-16 10:45
monicamlg
Rank: 2
等 级:论坛游民
帖 子:7
专家分:13
注 册:2011-3-18
收藏
得分:5 
# include <stdio.h>
# define A 8
# define B 12
# define C 0//C的赋值和D的赋值,决定于要算从C到D之间的数组数!例如C=0,和D=7就是算8组数组的列之和!
# define D 7
int main(void)
{
    int i, j ,total;
    int arry1[B];
    int arry[A][B] = {
        {3,1,0,0,0,1,0,0,0,0,2,0},
        {0,0,0,0,1,1,0,0,0,3,1,1},//  2  2  0  1  3  1  3  2  1  5  3  5
        {0,0,0,0,0,0,3,0,0,1,1,2},
        {0,1,0,1,2,0,0,1,0,1,1,0},
        {2,1,0,0,0,0,0,1,1,0,0,2},
        {1,1,0,1,0,1,1,0,1,1,0,0},
        {1,0,0,1,0,1,1,1,1,0,0,1},
        {1,0,0,0,3,0,1,0,1,0,1,0}
    };
       for(j = 0; j < B; ++j)
    {
        total = 0;
        for(i = C; i <= D; ++i)
        {
            total += arry[i][j];  
                                 
        }
        arry1[j]=total;   //比2楼的时间复杂度要小,少做了一次循环
        printf("%3d", arry1[j]);// arry1[] 便可以操作它了
        
    }
    putchar('\n');
   
    return 0;
}


[ 本帖最后由 monicamlg 于 2011-10-16 12:42 编辑 ]
2011-10-16 12:36
快速回复:数组问题
数据加载中...
 
   



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

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