C语言作业1-顺序选择结构设计-4分段函数求值

版权声明:所有分享的源代码仅供学习使用,欢迎分享转载,请注明出处 https://blog.csdn.net/weixin_43328024/article/details/85196730

C语言作业1-顺序选择结构设计-4分段函数求值

问题描述:
在这里插入图片描述
代码实现:

#include<stdio.h>
int main()
{
	double x;
	printf("请输入x的值:\n") ;
	scanf("%lf",&x);
	if(x < 0)
	{
		printf("%lf",x);
	}
	if(x >= 10 && x < 50)
	{
		x = 3 * x - 2;
		printf("%lf",x);
	}
	if(x >= 50 && x < 100)
	{
		x = 4 * x + 1;
		printf("%lf",x);
	}
	if(x >= 100)
	{
		x = 5 * x;
		printf("%lf",x);
	}
	return 0;
} 

运行结果:
在这里插入图片描述

欢迎各位大佬提出更优秀的解决方案。

猜你喜欢

转载自blog.csdn.net/weixin_43328024/article/details/85196730