有一函数,请编写程序,实现任意输入一个x的值,输出对应的值
来源:百度知道 编辑:UC知道 时间:2024/05/17 05:29:37
x (x<1)
y={ 2x+1 (1<=x<10)
5x-17 (x>=10)
y={ 2x+1 (1<=x<10)
5x-17 (x>=10)
#include <stdio.h>
main()
{
int x,y;
scanf("%d\n",&x);
if(x<1) y=x;
else if(x<10) y=2*x+1;
else y=5*x-17;
printf("%d\n",y);
}
#include<iostream.h>
void main()
{
int x;
cin>>x;
if(x<1)
{
y=x;
cout<<endl;
}
else if(x>=10)
{y=5*x-17;
cout<<y<<endl;}
else
y=2*x+1;
cout<<y<<endl;
}