#include<conio.h>
#include<stdio.h>
double fun(int n)
{int m=1;
double s=0.0;
do {s+=1.0/(m*(m+1));}
while(m<=n);
return s;}
main()
{system("cls");
printf("%f\n",fun(10));
getch();}
算s=1/(1*2)+1/(2*3)+....+1/(n*(n+1)) 当n=10时 函数值是0.909091
#include<conio.h>
#include<stdio.h>
double fun(int n)
{int m=1;
double s=0.0;
do {s+=1.0/(m*(m+1));}
while(m<=n);
return s;}
main()
{system("cls");
printf("%f\n",fun(10));
getch();}
算s=1/(1*2)+1/(2*3)+....+1/(n*(n+1)) 当n=10时 函数值是0.909091
do {s+=1.0/(m*(m+1)); ++m;}
截图:
#include<conio.h> #include<stdio.h> double fun(int n) {int m=1; double s=0.0; do {s+=1.0/(m*(m+1)); m++;//少了这个 } while(m<=n); return s;} main() {system("cls"); printf("%f\n",fun(10)); getch();}