1049:晶晶赴约会 和 1057:简单计算器 switch简介的练习答案

1049

#include 
#include
using namespace std;
int main()
{
	int a ;
	cin>>a;
	switch(a)
	{
		case 1 : cout<< "NO";break;
		case 3 : cout<< "NO";break;
		case 5 : cout<< "NO";break;
		default: cout<<"YES";
	}
	return 0;
} 

1057

#include 
#include
using namespace std;
int main()
{
	int a;
	int b;
	char c;
	cin>>a>>b>>c;
	switch(c)
	{
		case '+':cout<<a+b;break;
		case '-':cout<<a-b;break;
		case '*':cout<<a*b;break;
		case '/':
				if(b==0) cout<<"Divided by zero!";
				else cout<<(int)a/b;break;
		default :cout<<"Invalid operator!";
	}
	
	return 0;
} 

你可能感兴趣的:(C++)