标题:新手求解枚举问题,年份输入打出月份,请高手大神教教我,谢谢
只看楼主
wangxupei537
Rank: 1
等 级:新手上路
帖 子:23
专家分:2
注 册:2015-2-9
结帖率:75%
已结贴  问题点数:20 回复次数:8 
新手求解枚举问题,年份输入打出月份,请高手大神教教我,谢谢
定义一个枚举类型enum month描述1至12个月各用英文缩写表示,并且编写一个程序,使得输入一个年份,将这个年份的每个月的英文名全称以及月数输出。
我觉得这道题第一必须解决闰年平年问题,我使用了if else
可是枚举的Jan等月数,英文名怎么输出,实在不会。请各位高手帮忙
#include<stdio.h>
enum month { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
int main()
{  int year;
   char *monthDetail1[]={"January 31","February 28","March 31","April 30","May 31","June 30","July 31","August 31","September 30","October 31","Novmber 30","Decmber 31"};
   char *monthDetail2[]={"January 31","February 27","March 31","April 30","May 31","June 30","July 31","August 31","September 30","October 31","Novmber 30","Decmber 31"};
   scanf("%d",year);
   if(!(year%4)&&year%100||!(year%400))
      printf("%s\n",monthDetail2);
    else
   printf("%s\n",monthDetail1);

   return 0;
   }
搜索更多相关主题的帖子: 英文缩写 include 英文名 
2015-04-05 15:36
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
你确定没有打错字?

授人以渔,不授人以鱼。
2015-04-05 17:24
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
得分:0 
难道平年闰年的月数还不一样?

一片落叶掉进了回忆的流年。
2015-04-05 18:08
longwu9t
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:732
专家分:2468
注 册:2014-10-9
得分:20 
程序代码:
#include<stdio.h>

const char *m1[] = {"January 31", "February 28", "March 31", "April 30", "May 31", "June 30", "July 31", "August 31", "September 30", "October 31", "Novmber 30", "Decmber 31"};
const char *m2[] = {"January 31", "February 29", "March 31", "April 30", "May 31", "June 30", "July 31", "August 31", "September 30", "October 31", "Novmber 30", "Decmber 31"};

void prt(const char *m[]) {
    int i;
    for(i = 0; i < 12; i++)
        printf("%s\n", m[i]);
}

int main(void) {

    int year;
    
    scanf("%d", &year);

    if((0 == year % 4 && 0 != year % 100) || (0 == year % 400))
        prt(m2);

    else
        prt(m1);

    return 0;
}


Only the Code Tells the Truth             K.I.S.S
2015-04-05 19:07
wangxupei537
Rank: 1
等 级:新手上路
帖 子:23
专家分:2
注 册:2015-2-9
得分:0 
回复 3楼 诸葛欧阳
不好意思。。。是每个月的天数。不一样
2015-04-06 09:45
wangxupei537
Rank: 1
等 级:新手上路
帖 子:23
专家分:2
注 册:2015-2-9
得分:0 
回复 2楼 TonyDeng
及日数。。。。
2015-04-06 09:46
wangxupei537
Rank: 1
等 级:新手上路
帖 子:23
专家分:2
注 册:2015-2-9
得分:0 
回复 4楼 longwu9t
谢谢您,如果代码里有什么不懂的,我会询问您的!
2015-04-06 09:50
longwu9t
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:732
专家分:2468
注 册:2014-10-9
得分:0 
假如说一定要用上枚举
可以这样

程序代码:
#include<stdio.h>

const char *m1[] = {"January 31", "February 28", "March 31", "April 30", "May 31", "June 30", "July 31", "August 31", "September 30", "October 31", "Novmber 30", "Decmber 31"};
const char *m2[] = {"January 31", "February 29", "March 31", "April 30", "May 31", "June 30", "July 31", "August 31", "September 30", "October 31", "Novmber 30", "Decmber 31"};

void prt(const char *m[]) {
    enum month { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
    int i;
    for(i = Jan; i <= Dec; i++)
        printf("%s\n", m[i]);
}

int main(void) {

    int year;
    
    scanf("%d", &year);

    if((0 == year % 4 && 0 != year % 100) || (0 == year % 400))
        prt(m2);

    else
        prt(m1);

    return 0;
}

Only the Code Tells the Truth             K.I.S.S
2015-04-06 12:57
linonon
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2015-4-6
得分:0 
班长你好
2015-04-06 20:01



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




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

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