#include <stdio.h>
#include <stdlib.h>
float fun(int n)
{
int i,b=1;
float sum=0,a;
for(i=0; i<n; i++)
{
a=b*(b+1);
b++;
sum+=1/a;
}
return sum;
}
int main()
{
int n;
printf(“输入n的值:”);
scanf("%d",&n);
printf(“S=%f”,fun(n));
}
#include <stdio.h>
#include <stdlib.h>
float fun(int n)
{
int i,b=1;
float sum=0,a;
for(i=0; i<n; i++)
{
a=b*(b+1);
b++;
sum+=1/a;
}
return sum;
}
int main()
{
int n;
printf(“输入n的值:”);
scanf("%d",&n);
printf(“S=%f”,fun(n));
}