Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
计算下列表达式值:
Input
输入x和n的值,其中x为非负实数,n为正整数。
Output
输出f(x,n),保留2位小数。
Sample Input
3 2
Sample Output
2.00
Hint
Source
因为在每一次中的操作都是相似的,所以可以用循环实现,再定义一个求一次函数,用循环调用n次就可以了
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//math函数库是数学函数库,因为下面要调用sqrt函数;
double f(double a,int b)
{
a += b;
return sqrt(a);
}
int main()
{
int n ,i;
double x;
scanf("%lf%d",&x,&n);
/*因为根据上面的式子可以看出,从加“1”再开方,再加“2”再开方,一直到n,
所以找好可以利用循环中的控制变量“i”;*/
for(i=1;i<=n;i++)
{
x = f(x,i);
}
printf("%.2lf\n",x);
return 0;
}