编写一个C程序,描述如下数学函数关系:当1<x<5时,y的值为2x+3;当x<1时,y的值为3x-1;当x为其它值时,y的值为x。

编写一个C程序,描述如下数学函数关系:当1<x<5时,y的值为2x+3;当x<1时,y的值为3x-1;当x为其它值时,y的值为x。


#include <stdio.h>
int main()
{
    int x, y;
    if (x > 1 && x < 5)
    {
        y = 2 * x + 3;
    }
    else if (x < 1)
    {
        y = 3 * x - 1;
    }
    else
    {
        y = x;
    }
    return 0;
}

供参考:

#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d",&x);
    if (x < 1)
       y = 3*x - 1;
    else if(x > 1 && x < 5)
       y = 2*x + 3;
    else
       y = x;
    printf("y=%d",y);
    return 0;
}