将数字转换为一年中一个月的程序 [英] program that converts the number to a month in a year

查看:219
本文介绍了将数字转换为一年中一个月的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问是否有人可以帮助我编写一个读取整数值的程序,假设该数字是一年中的一个月并显示月份名称.

我将不胜感激.
谢谢

[已更新]

我只是一个学生,您能帮我编写完整的程序吗?
[/Update]

Hi I would like to ask if someone can help me write a program that read an integer value, assumes that number is a month in a year and prints the month name.

I would appreciate any help.
thank you

[Updated]

im just a student can you help me write the complete program??
[/Update]

推荐答案

这很简单:只需使用月份名称初始化const char *数组并为其建立索引加上月份号.
:)

That''s trivial: just initialize array of const char * with month names and index it with the month number.
:)

jack_mawats写道:
jack_mawats wrote:

我只是一个学生,你能帮我写完整的程序吗?

im just a student can you help me write the complete program??



嗨~~~我这样写:希望它能给您一些帮助~~
hi~~~I write this : wish it can give you some help~~
#include<stdio.h>
int main()
{
    int a;
    printf("please input a number:");
    scanf("%d",&a);
    switch(a)
    {
    case 1:
        printf("JANUARY");
        break;
    case 2:
        printf("FEBRUARY");
        break;
    case 3:
        printf("MARCH");
        break;
    case 4:
        printf("APRIL");
        break;
    case 5:
        printf("MAY");
        break;
    case 6:
        printf("JUNE");
        break;
    case 7:
        printf("JULY");
        break;
    case 8:
        printf("AUGUST");
        break;
    case 9:
        printf("SEPTEMBER");
        break;
    case 10:
        printf("OCTOBER");
        break;
    case 11:
        printf("NOVEMBER");
        break;
    case 12:
        printf("DECEMBER");
        break;
    default:
        printf("can not find this month in a year!");
    }
}


这篇关于将数字转换为一年中一个月的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆