修改前
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main{)
[
int x,y;
cin>>x;
if (x<1) y=x;
else if (x>=10) y=3x=11;
else y=2x-1;
cout<<y<<endl;
return 0;
]
修改后
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin>>x;
if (x<1)
{
y=x;
}
else if(x>=10)
{
y=3*x-11;
}
else
{
y=2*x-1;
}
cout<<y<<endl;
return 0;
}
心得 在if语句中用{}括起表达式,对于3乘以x,不能写成3x,而是3*x!!!!!
分段函数
最新推荐文章于 2023-12-18 08:00:00 发布