| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1165 人关注过本帖
标题:C语言的指针问题
只看楼主 加入收藏
yk394159040
Rank: 2
等 级:论坛游民
帖 子:12
专家分:10
注 册:2016-7-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
C语言的指针问题
#include<stdio.h>
#define YEARS 5
#define MONTHs 12
int main(void)
{
     const float rain[YEARS][MONTHs]=
    {
        //初始化数组2000-20004年降水量
        {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
        {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
        {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
        {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
        {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2},
    };
    int year,month;
    float subtot,total;
    printf("Year   Rainfall(inches)\n");
    for(year=0,total=0;year<YEARS;year++)
    {
        for(month=0,subtot=0;month<MONTHs;month++)
            subtot+=*(*(rain+year)+month);      //这一行怎么理解?
        printf("%5d%5.1f\n",2000+year,subtot);
        total+=subtot;  
    }
    printf("The yearly average is %.1f\n",total/YEARS);
    printf("MONTHLY AVERAGEE:\n\n");
    printf("Jan\tFeb\tMar\tApr\tMay\tJun\tJul\tAug\tSep\tOct\tNov\tDec\n");
    for(month=0;month<MONTHs;month++)
    {
        for(year=0,subtot=0;year<YEARS;year++)
            subtot+=*(*(rain+year)+month);
        printf("%.1f\t",subtot/YEARS);
    }
    printf("\n");
    return 0;
   
}
搜索更多相关主题的帖子: C语言 指针 year printf for 
2017-09-20 16:29
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
subtot+=*(*(rain+year)+month);      //这一行怎么理解?
subtot += rain[year][month];
2017-09-20 16:39
九天冥盟
Rank: 2
等 级:论坛游民
威 望:1
帖 子:77
专家分:20
注 册:2015-7-14
收藏
得分:10 
大哥,这代码是你自己写的吗?
2017-09-22 16:24
快速回复:C语言的指针问题
数据加载中...
 
   



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

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