106/10/17作業(求1+1/2+1/3....+1/n)
程式碼:
/*
1+1/2+1/3...+1/n
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
double sum=0.0;
int n=1,m;
printf("請輸入要求總合:");
scanf("%d", &m);
do
{
sum=sum+(double)1/n;
printf("總和= %lf n=%d\n",sum,n);
n=n+1;
}while(sum< m);
printf("總和= %lf n=%d\n",sum,n-1);
}