1. 程式人生 > >輸入一個0~6的整數,轉換成星期輸出。

輸入一個0~6的整數,轉換成星期輸出。

#include <iostream>
using namespace std;
int main()
{
    int day;
    cin>>day;
    switch(day)
    {
        case 0:
            cout<<"Sunday"<<endl;break;
        case 1:
            cout<<"Monday"<<endl;break;
        case 2:
            cout<<"Tuesday"<<endl;break;
        case 3:
            cout<<"Wednesday"<<endl;break;
        case 4:
            cout<<"Thurday"<<endl;break;
        case 5:
            cout<<"Friday"<<endl;break;
        case 6:
            cout<<"Saturday"<<endl;break;
        default:
            cout<<"Day out of range Sunday...Saturday"<<endl;break;
    }
    return 0;
}

執行結果如下圖: