第二周项目四

来源:互联网 发布:linux改为中文 编辑:程序博客网 时间:2024/06/05 12:43
/* *copyright(c) 2016,烟台大学计算机学院 *All rights reserved *文件名称:test.cpp *作者:徐伟 *版本:v6.0 * *问题描述: 计算输出pai的值 *输入描述:无 *程序输出:输出答案*/#include<iostream>#include<cmath>using namespace std;int main(){double sum=0;int temp=-1;double shu=1;int t=2,y=2;while(fabs(shu)>=1e-5){sum=sum+shu;t=2*y-1;shu=1.0/t;shu=shu*temp;temp=-temp;y++;}printf("%f",4*sum);}

0 0