C 练习实例24

C 语言教程 · 2019-02-21 17:59:24

题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。

程序分析:请抓住分子与分母的变化规律。

程序源代码:

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include <stdio.h> int main() { int i,t; float sum=0; float a=2,b=1; for(i=1;i<=20;i++) { sum=sum+a/b; t=a; a=a+b; b=t; } printf("%9.6f\n",sum); }

以上实例输出结果为:

32.660263

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

Transcending CSS

Transcending CSS

Andy Clarke、Molly E. Holzschlag / New Riders / November 15, 2006 / $49.99

As the Web evolves to incorporate new standards and the latest browsers offer new possibilities for creative design, the art of creating Web sites is also changing. Few Web designers are experienced p......一起来看看 《Transcending CSS》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具