依次读入n和m,循环m次计算n的平方根并更新n,统计n的平方根的和,最后按格式化"%.2lf"保留两位小数进行输出,需要注意的是n的类型与sqrt的返回值类型。
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
void fun(int n, int m)
{
double rst = 0.0;
double tmp = n;
while(m--)
{
rst += tmp;
tmp = sqrt(tmp);
}
printf("%.2lf\n",rst);
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m) != EOF)
{
fun(n,m);
}
return 0;
}
京公网安备 11010502036488号