C语言程序设计基础01 ------ 计算分数不等式

【题目来源】                                                                                    

  《趣味C程序设计集锦》p4

【题目分析】                                                                                  

  简单题......

  s += 1.0/++i;

【题目代码】                                                                                  

 1 /*============================================================================*\
 2 * 计算 < 1 + 1/2 + 1/3 + ··· + 1/m < n+1
 3 * @date 3/12/2013
 4 * VC++ 6.0
 5 \*============================================================================*/
 6 #include <stdio.h>
 7 #include <stdlib.h>
 8 
 9 int main()
10 {
11     long c, d , i = 0, n;
12     double s = 0.0;
13     printf("计算 < 1 + 1/2 + 1/3 + ··· + 1/m < n+1\n");
14     printf("\n请输入n:");
15     scanf("%ld", &n);
16 
17     while(s < n){
18         s += 1.0/++i;
19     }
20 
21     c = i;
22 
23     while(s < n+1){
24         s += 1.0/++i;
25     }
26 
27     d = i-1;
28 
29     printf("\n满足不等式的m为:%ld ≤ m ≤ %ld \n", c,d);
30 
31     return 0;
32 }

【测试结果】                                                                                   

posted @ 2013-03-12 01:52  Cocoon  阅读(571)  评论(0编辑  收藏  举报