zoukankan      html  css  js  c++  java
  • 输出月份英文名 (30 分)

    6-2 输出月份英文名 (30 分)
    本题要求实现函数,可以返回一个给定月份的英文名称。
    函数接口定义:
    char *getmonth( int n );
    函数getmonth应返回存储了n对应的月份英文名称的字符串头指针。如果传入的参数n不是一个代表月份的数字,则返回空指针NULL。
    裁判测试程序样例:

    include <stdio.h>

    char *getmonth( int n );

    int main()
    {
    int n;
    char *s;

    scanf("%d", &n);
    s = getmonth(n);
    if ( s==NULL ) printf("wrong input!
    ");
    else printf("%s
    ", s);
    
    return 0;
    

    }

    /* 你的代码将被嵌在这里 */
    输入样例1:
    5
    输出样例1:
    May
    输入样例2:
    15
    输出样例2:
    wrong input!

    答案:
    char *getmonth( int n )
    {
    switch(n){
    case 1:return "January";
    case 2:return "February";
    case 3:return "March";
    case 4:return "April";
    case 5:return "May";
    case 6:return "June";
    case 7:return "July";
    case 8:return "August";
    case 9:return "September";
    case 10:return "October";
    case 11:return "November";
    case 12:return "December";
    default:return NULL;
    }
    }

  • 相关阅读:
    PHP 学习轨迹
    beego 遇到的一些问题
    Fiddler 502问题
    SourceTree
    Trait
    PHP PSR 标准
    解决MySQL联表时出现字符集不一样
    Git 代码管理命令
    PHP 运行相关概念
    CentOS 7
  • 原文地址:https://www.cnblogs.com/1112zx/p/10544681.html
Copyright © 2011-2022 走看看