有一个函数,编写程序,输入x,输出y的值。
c语言程序源码:
#include <stdio.h>
double calculate_y(double x) {
if (x < 1) {
return x; // y = x for x < 1
} else if (x >= 1 && x < 10) {
return 2 * x - 1; // y = 2x - 1 for 1 <= x < 10
} else {
return 3 * x - 11; // y = 3x - 11 for x >= 10
}
}
int main() {
double x, y;
printf("Enter the value of x: ");
scanf("%lf", &x); // Read a double value for x
y = calculate_y(x); // Calculate y based on x
printf("The value of y is: %lf\n", y); // Output the result
return 0;
}