注册 登录
编程论坛 C语言论坛

求助大佬,要求求一个分段函数的值,程序哪错了,纯新人

林初尧 发布于 2022-10-04 22:42, 1087 次点击
#include <stdio.h>
int main()
{
    int x;
    printf("intput 'x'num\n");
    scanf_s("%d",&x);
    if (x < 1) {
        printf("x的值为:\n",x);}
   
    x = 2 * x - 1;
    if (1 <= x < 10) {
        printf("x的值为:\n",2*x-1); }
   
    x = 3 * x - 11;
    if (x >= 10) {
        printf("x的值为:\n", 3 * x - 11); }
    return 0;
}

[此贴子已经被作者于2022-10-4 22:44编辑过]

3 回复
#2
林初尧2022-10-04 22:53
#include <stdio.h>
#include <math.h>
int main(){
int x,y;
printf("请输入X的值:\n");
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",y);
}
#包括<stdio.h>
#包括<math.h>
Int main(){
INT x,y;
printf("请输入X的值:\n");
扫描量(“%d”,&x);
If(x<1){
Y =x;
}
如果(x>=1&x<10){
Y=2*x-1;
}
如果(x>=10){
Y=3*x-11;
}
printf("Y的值为:%d", y);
}
#3
md000000002022-10-05 22:13
程序代码:

#include <stdio.h>
int main()
{
    int x;
    printf("intput 'x'num\n");
    scanf("%d",&x);
    if (x < 1) {
        printf("x的值为:%d\n",x);}
   
    x = 2 * x - 1;
    if (1 <= x < 10) {
        printf("x的值为:%d\n",2*x-1); }
   
    x = 3 * x - 11;
    if (x >= 10) {
        printf("x的值为:%d\n", 3 * x - 11); }
    return 0;
}
#4
apull2022-10-05 23:24
你这里
x = 2 * x - 1;
x = 3 * x - 11;
要求算2次么?
1