0
点赞
收藏
分享

微信扫一扫

C语言100题练习计划 51——求和并输出对应英文单词

🥇C语言100题练习专栏计划目的:巩固练习C语言,增强上机、动手实践能力,交流学习!

一、问题呈现

1.问题描述

Problem Description

a+b==1时输出one,
a+b==2时输出two,
a+b==3时输出three,
a+b==4时输出four,
a+b==5时输出five,
a+b==6时输出six,
a+b==7时输出seven,
a+b==8时输出eight,
a+b==9时输出nine,
否则输出None(提示:switch语句)

2.输入输出

Input

输入两个整数a,b,以空格隔开

Output

输出求和后相应的单词

3.测试样例

样例1

Sample Input

3 5

Sample Output

eight
样例2

Sample Input

2 4

Sample Output

six

二、源码实现

#include<iostream>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	int sum;
	sum=a+b; //求和
	switch (sum) //switch选择相应结果输出
    {
		case 1:
			cout<<"one"<<endl;
			break;
		case 2:
			cout<<"two"<<endl;
			break;
		case 3:
			cout<<"three"<<endl;
			break;
		case 4:
			cout<<"four"<<endl;
			break;
		case 5:
			cout<<"five"<<endl;
			break;
		case 6:
			cout<<"six"<<endl;
			break;
		case 7:
			cout<<"seven"<<endl;
			break;
		case 8:
			cout<<"eight"<<endl;
			break;
		case 9:
			cout<<"nine"<<endl;
			break;			
		default:
			cout<<"None"<<endl;
			break;
	}
	return 0;
}

三、测试图

为了使整体内容简洁,此处只展示一组测试数据结果。

举报

相关推荐

0 条评论