“输出一个0~6的整数,转换为星期”怎样做

来源:6-5 数组的应用(一)

qingni

2015-12-14 15:48

“输出一个0~6的整数,转换为星期”怎样做

写回答 关注

3回答

  • 越飞越高
    2016-11-02 19:25:39

    #include<iostream.h>
    int main()
    {
    int a;
    cin>>a;
    switch(a)
    {
    case 0:cout<<"Sunday"<<endl;
    break;
    case 1:cout<<"Monday"<<endl;
    break;
    case 2:cout<<"Tuseday"<<endl;
    break;
    case 3:cout<<"Wednesday"<<endl;
    break;
    case 4:cout<<"Thursday"<<endl;
    break;
    case 5:cout<<"Friday"<<endl;
    break;
    case 6:cout<<"Saturday"<<endl;
    break;
    default:cout<<"Please input 0~6"<<endl;
    break;
    }
    return 0;
    }

  • RockenRoll
    2015-12-14 16:10:46

    这个判断可以去掉

  • RockenRoll
    2015-12-14 16:09:50

    int i ;
        printf("请输入一个0~6的数");
        scanf("%d",&i);
        if (i>=0&&i<=6) {
            switch (i) {
                case 0:
                    printf("星期日");
                    break;
                case 1:
                    printf("星期一");
                    break;
                case 2:
                    printf("星期二");
                    break;
                case 3:
                    printf("星期三");
                    break;
                case 4:
                    printf("星期四");
                    break;
                case 5:
                    printf("星期五");
                    break;
                case 6:
                    printf("星期六");
                    break;
                    
                default:
                    printf("输入有误");
                    break;
            }
        }

C语言入门

C语言入门视频教程,带你进入编程世界的必修课-C语言

926215 学习 · 20797 问题

查看课程

相似问题