游客 Signup | Login
中文 | En

3461 - 计算分段函数

通过次数

0

提交次数

0

Time Limit : 1 秒 Memory Limit : 128 MB

计算分段函数,

输入x,打印出y值。流程图如图所示。

Input

输入一个整数 x。(-50<=x<=50)

Output

输出y的值。保留6位小数。

Examples

Input Format

1
0
-1

Output Format

0.367879
1.000000
-0.367879

Solution C

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main()
{
   // freopen("in","r",stdin);
   // freopen("out","w",stdout);

    int x;
	double y;
    while(scanf("%d", &x)!=EOF)
    {
	if (x > 0)
	{
		y = exp(-x);
	}
	else if (x == 0)
	{
		y = 1;
	}
	else
	{
		y = -exp(x);
	}
	printf("%lf\n", y);


    }
  return 0;
}

Solution C++

#include<stdio.h>
#include<math.h>
int main()
{
	int x;
	float y;
	while(scanf("%d",&x)!=EOF)
	{
		if((x>=-50)&&(x<0))
		{
			y = -exp(x);
		}
		if((x<=50)&&(x>0))
		{
			y = exp(-x);
		}
		if(x == 0)
		{
			y = 1;
		}
		printf("%.6f\n",y);
	}
    return 0;
}