Sn=2/1+3/2+4/3+...+(n+1)/n,求Sn不超过50的最大值.(C语言代码)_百度知...
发布网友
发布时间:2024-10-15 12:32
我来回答
共1个回答
热心网友
时间:2024-10-16 09:22
#include <stdio.h>
double sn(int n)
{
double ret = 0;
for (int i = 1; i <= n; i++)
{
ret += (i + 1) / (double)i;
}
return ret;
}
int main()
{
int n = 1;
double max = 0;
while (sn(n)<=50)
{
if (sn(n) > max)
max = sn(n);
n++;
}
printf("最大值:%lf", max);
return 0;
}
//最大值为:49.394948