您的位置:首页 > 编程语言 > C语言/C++

C语言实验——计算表达式

2017-10-20 09:39 239 查看


C语言实验——计算表达式

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic


Problem Description

计算下列表达式值: 


 


Input

输入x和n的值,其中x为非负实数,n为正整数。


Output

输出f(x,n),保留2位小数。


Example Input

3 2



Example Output

2.00

#include <stdio.h>
#include <math.h>
double f(double x, int n);
int main()
{
double x,result;
int n;
scanf("%lf%d",&x,&n);
result=f(x,n);
printf("%.2lf\n",result);
return 0;
}
double f(double x,int n)
{
double f=0;
int i;
for(i=1;i<=n;i++)
{
if(i==1)
f=sqrt(i+x);
else
f=sqrt(i+f);
}
return f;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言