第二周 项目四
2016-03-15 19:40
120 查看
/* *Copyright(c)2014,烟台大学计算机与控制工程学院 *Allrights reserved. *文件名称:test.cpp *作者:肖雪 *完成日期:2016年3月15日 *版本号:v1.0 * *问题描述: * (1)用如下公式求π的近似值(计算直到最后一项的绝对值小于10E-5) * π/4=1-1/3+1/5-1/7+... * (2)设计程序,输出Fibonacci数列:1 1 2 3 5 8 13 21 34 55 89...直到这个数字超过1000 *程序输出:(1)近似值 (2)数列 */ //(1) #include<iostream> using namespace std; int main() { int i; int a=-1; double pai,sum=0; for(i=1;i<100000;i+=2) { a=-a; sum=sum+(1.0/i)*a; } pai=4*sum; cout<<"π的近似值:"<<pai<<endl; return 0; }
//(2) #include<iostream> using namespace std; int main() { int i=1,t; int sum=0; cout<<i<<sum<<endl; while(sum<=10000) { t=sum; sum=i; i=t; sum+=i; cout<<sum<<endl; } return 0; }
相关文章推荐
- 51nod--1242 斐波那契数列第N项 (矩阵乘法优化)
- RAM之程序运行时数据和代码加载
- 最长上升子序列
- Cannot reload AVD list
- 1.ARM基础概念及芯片平台
- Python正则表达式,re模块
- 基于Face++实现的人脸检测(年龄检测)Android程序
- 如何居中一个浮动元素?
- cocos2d-x 关于tilemap滚动时黑线闪动的问题
- OpenGL with PyOpenGL Python and PyGame p.4-Moving the player automatically towards the cube
- ZOJ 3497 Mistwald【矩阵快速幂】【图论】
- Android设计模式之代理模式 Proxy
- 记录合法的最长的串
- 图论面试题
- android.mk编译apk在64位机器内运行so库报错
- JavaScript子文本传到父文本框显示
- 防止站点数据被採集——成佩涛黑客
- Tomcat源码解析(五):Connector连接器的初始化和启动流程
- Python——编写函数装饰器
- Two Strings