C语言网-分段函数求值

题目描述

有一个函数
y={ x x<1
| 2x-1 1<=x<10
{ 3x-11 x>=10

写一段程序,输入x,输出y

直接把题目给狠狠的入了,下面是思路

#include <stdio.h>

int main(void){
	int x=0,y=0;
	scanf("%d",&x);
	if(x<1){
		y=x;
	}else if(1<=x && x<10){
		y=2*x-1;
	}else{ 
		y=3*x-11;
	}
	printf("%d",y);
	return 0;
}
posted @ 2025-01-01 22:09  论码  阅读(20)  评论(0)    收藏  举报