我有个喵喵酱


私信TA

用户名:firstblond

访问量:8650

签 名:

每天都要进步一点点!

等  级
排  名 709
经  验 3911
参赛次数 0
文章发表 19
年  龄 21
在职情况 学生
学  校 家里蹲
专  业

  自我简介:

解题思路:
                    (1).设置一个输入列数a,用于循环次数;

                    (2).设置一个用于保存的数列和的常量b,并且初始化b=0;            

                    举例:第一列:a=1,b+=2/1,分子是2,分母是1,

                            第二列:a=2,b+=3/2,分子是3,分母是2,

                            第三列:a=3,b+=5/3,分子是5,分母是3,

                            第四列,a=4,b+=8/5,分子是8,分母是5,

                        由此可知:

                                        (1).当分子第K项时,分母Z等于K-Z项.

                                        (2).当K进入下一项时候,肯定是当前K=K+Z(8/5,分子8=5+3)

                                        (3).分母Z=K-Z相当于这一次分子数K减去上一次分母数Z(8/5,分母5=8-3)

                    所以用一个循环来求出,i表示次数,每次循环,b都保存每次的值

注意事项:
                    
参考代码:

                楼主自己写的思路,可以供参考:

                        

                            

                                                    #include<stdio.h>
                                                    int main(void)
                                                    {
                                                             double a,b=0;                
                                                             double k=2.0,z=1.0;                 //注意精度
                                                             scanf("%lf",&a);                        //读取用户输入的次数
                                                             for(int i=0;i<a;i++)                      
                                                             {
                                                                          b=b+k/z;                        //b保存每一次的和
                                                                          k+=z;                            //为下一次分子K做准备
                                                                          z=k-z;                            //为下一次分母Z做准备
                                                              }
                                                              printf("%.2lf",b);                        //输出保留两位小数
                                                              return 0;
                                                      }

                            

    


                       有啥不懂的小伙伴可以在评论下方留言哦(づ ̄3 ̄)づ╭❤~O(∩_∩)O

 

0.0分

0 人评分

  评论区

  • «
  • »