C语言问题知道的答一下

来源:百度知道 编辑:UC知道 时间:2024/06/04 15:03:47
x(x<1)
y{ 2x-1(1<=x<10)
3x-11(x>=10)
用scanf函数输入x值,求y值..
运行程序,输入x值(分别求x<1,1~10,x>=10)
检查Y值的情况..

scanf("%d",&x);
if(x<1)
y=x;
else if(x>=1&&x<10)
y=2*x-1;
else
y=3*x-11;
printf("y=%d\n",y);

int func(int x)
{
if(x<1)return x;
if(x<10)return (2*x-1);
return (3*x-11);
}
void main()
{
int x;
printf("please input x:");
scanf("%d",&x);
printf("\nresult: y=%d",func(x));
}

#include <stdio.h>
void main()
{
int x,y;
scanf("%d",&x);
if(x<1)
y=x;
else if(x<10)
y=2*x-1;
else
y=3*x-11;
printf("y=%d\n",y);
}