求救。c语言,有一个函数y=x(x<1),y=2x-1(1<=x<10),y.=3x-11(x>=10).写一段程序,输入x,输出y值.怎么做?

2025-01-03 11:24:37
推荐回答(1个)
回答1:

char X[4];
int x = 0 , y = 0;
printf("请输入X值:");
scanf("%s",X);
x = atoi((char *)X);
if(x < 1)
y = x;
else if(x < 10 && x >= 1)
y = (2 * x - 1);
else if(x >= 10)
y = 3 * x - 11;

printf("Y的值为:%d\n",y);