游客 Signup | Login
中文 | En

2592 - C二级辅导-分段函数

有一个函数如下,写一程序,输入x,输出y值。

保留两位小数

Input

Output

Examples

Input

1

Output

1.00

Solution C

#include <stdio.h>

int main() {
    float x;
    scanf("%f", &x);
    if (x >= 1 && x < 10) {
        x = 2 * x - 1;
    } else if (x >= 10){
        x = 3 * x - 11;
    }
    printf("%.2f\n", x);
    return 0;
}

Solution C++

#include <stdio.h>
int a[100000];
int main()
{
	double x;
	while(scanf("%lf",&x)!=EOF)
	{
		if(x<1)
		printf("%.2lf\n",x);
		if(x>=1&&x<10)
		printf("%.2lf\n",2*x-1);
		else
		printf("%.2lf\n",3*x-11);
	}
	return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题