1)插入如下代码内容
例如将以下代码段进行设置
#include <iostream>
#include <Cmath>
using namespace std;
int main()
{
double x,y;
int c;
cout <<"请输入大于0 的实数值x"<<endl;
cin >> x;
if(x < 0)
cout<<"Input error!"<<endl;
else
{
c = int (x)/2;
switch(c)
{
case 0:
y = x;break;
case 1:
case 2:
y = x * x + 1;break;
case 3:
case 4:
y = sqrt(x + 1);break;
default:
y = 1/(x + 1);break;
}
cout <<"y = "<< y <<endl;
}
}
/*****************************************************/
2)操作方式
例如将以下代码段进行设置
#include <iostream>
#include <Cmath>
using namespace std;
int main()
{
double x,y;
int c;
cout <<"请输入大于0 的实数值x"<<endl;
cin >> x;
if(x < 0)
cout<<"Input error!"<<endl;
else
{
c = int (x)/2;
switch(c)
{
case 0:
y = x;break;
case 1:
case 2:
y = x * x + 1;break;
case 3:
case 4:
y = sqrt(x + 1);break;
default:
y = 1/(x + 1);break;
}
cout <<"y = "<< y <<endl;
}
}