C语言的代码用if-else和switch分别一个

编写程序,输入1~5之间的整数,将他们转换成对应的中文。其中要求:1转换成西安交通大学,2转换成西北工业大学,3转换成西安电子科技大学,4转换成第四军医大学。要求用两种方法完成。
1)用if-else语句编写;2)用switch语句编写

switch:

#include <iostream>
using namespace std;
int main()
{
    int i = 0;
    cout << "Input:";
    cin >> i;
    switch (i)
    {
    case 1:
        cout << "西安交通大学" << endl;
        break;
    case 2:
        cout << "西北工业大学" << endl;
        break;
    case 3:
        cout << "西安电子科技大学" << endl;
        break;
    case 4:
        cout << "第四军医大学" << endl;
        break;
    default:
        cout << "输入有误!" << endl;
        break;
    }
    return 0;
}

if else:

#include <iostream>
using namespace std;
int main()
{
    int i = 0;
    cout << "Input:";
    cin >> i;
    if (i == 1)
        cout << "西安交通大学" << endl;
    else if (i == 2)
        cout << "西北工业大学" << endl;
    else if (i == 3)
        cout << "西安电子科技大学" << endl;
    else if (i == 4)
        cout << "第四军医大学" << endl;
    else
        cout << "输入有误!" << endl;
    return 0;
}

有帮助望采纳