c++中下列问题用switch语句怎么编写

2024-11-04 20:24:27
推荐回答(2个)
回答1:

switch是一个开关语句,和case配套使用,和ifelse判断语句差不多,switch语句是用于多分支语句进行条件判断。下例为用switch语句编写的四则运算:#includevoidmain(){doubleN1,N2;charOperation;printf("输入运算的两个数");scanf("%lf%lf",&N1,N2);printf("请输入运算符(+,-,*,/):");switch(Operation){case'+':printf("%lf%c%lf=%lf",N1,N2,Operation,N1+N2);break;case'-':printf("%lf%c%lf=%lf",N1,N2,Operation,N1-N2);break;case'*':printf("%lf%c%lf=%lf",N1,N2,Operation,N1*N2);break;case'/':printf("%lf%c%lf=%lf",N1,N2,Operation,N1/N2);break;}}

回答2:

y = "
cin > y = "<.7*x <#include<< <

int main()
{
int x;
break; endl; <.9*x < y = "<
case 1;<
switch(x/<
using namespace std;> 0;iostream> ":
cout < endl;<<:
cout << "< endl; "
case 3; 0;1000)
{
case 0:
cout << x << y = "
case 2.8*x << <:
cout <
break; < x;
int y; 0; " endl;
break;
break