5-5(求 1+1/2+1/3+1/4+.....+1/n > m 時 n?)
/*問題
求 1+1/2+1/3+1/4+.....+1/n > m 時 n?
(例如輸入 m=10 n=?)
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float sum=1;
int m,n=1;
printf("正修科大 40404113 郭怡勝 \n");
printf("請輸入m之值=>");
scanf("%d",&m);
printf(" n => 1+1/2+1/3+1/4+.....+1/n = ?\n");
printf("\n %d => 1+1/2+1/3+1/4+.....+1/n = %f \n",n,sum);
while( sum <= m )
{
n++;
sum = sum + 1.0 / n;
printf(" %d => 1+1/2+1/3+1/4+.....+1/n = %f \n",n,sum);
}
{
if( sum <= m);
printf("\n當 m => %d 時,n = %d",m,n);
}
return 0;
}