c语言题目编一个程序,输入X的值,按下列公式计算并输出Y的值

2024-10-31 02:49:55
推荐回答(3个)
回答1:

#include
int main(){
int x,y;
printf("输入x的值:"); 
scanf("%d",&x);
if(x<=1)y=x;
else if(x>1&&x<10)y=2*x-1;
else if(x>=10)y=3*x-11;
printf("y=%d\n",y);
return 0;
}

回答2:

#include
int main()
{
int x,y;
printf("please input a number:\n");
scanf("%d\n",&x);
if(x<=1)
{
y=x;
printf("y=%d\n",y);
}
else if(x>1&&x<10)
{
y=2*x-1;
printf("y=%d\n",y);
}
else
{
y=3*x-11;
printf("y=%d\n",y);
}
return 0;
}

回答3:

#include
void main(){
float x;
printf("请输入x=");
scanf("%f",&x);
if(x<=1) printf("y=%g",x);
else if (x<10) printf("y=%g",2*x-1);
else printf("y=%g",3*x-11);
}