C语言编程 求分段函数的值

如题所述

第1个回答  2012-06-16
#include<stdio.h>
#include<math.h>

void main()
{
int x;
float Y;
printf("please input x\n");
scanf("%d",&x);
if(x > 0)
Y = 1 + exp(x); //数学函数,计算e的x次方
else if(x == 0)
Y = 1;
else
Y = log(x * x); //数学函数,计算x的平方,以e为底
printf("%.4f\n",Y);
}

please input x
0
1.0000
Press any key to continue

please input x
1
3.7183
Press any key to continue

please input x
-2
1.3863
Press any key to continue本回答被网友采纳
第2个回答  2012-06-16
#include<stdio.h>
#include<math.h>
void main()
{
double x=0;
double y=0;
printf(" 请输入x\n")
scanf("%ld",&x);
if(x==0)
y=1;
else if(x<0)
y=1+e^x;
else if(x>0)
y=axp(x);
}

}
第3个回答  2012-06-16
#include <math.h>
...
int x;
double y;
if(x>o) y=1+exp(x);
else if(x=0) y=1;
else y=2*log(x);
相似回答