正在加载图片...
4.1.1程序解析一求π的近似值#include<math.h>pi=3.141613int main(void)int denominator, flag;item=0.0 ?double item, pi;flag = 1; denominator = 1 ; item = 1.0; pi = 0;while(fabs(item)>=0.0001)fabs(item) < 0.0001item = flag * 1.0 / denominator;pi =pi + item;flag = -flag;denominator = denominator +2;7pi =pi * 4;printf (“pi =%fin", pi);ireturn O;1#include <math.h> int main(void) { int denominator, flag; double item, pi; flag = 1; denominator = 1 ; item = 1.0; pi = 0; while(fabs (item) >= 0.0001) { item = flag * 1.0 / denominator; pi = pi + item; flag = -flag; denominator = denominator +2; } pi = pi * 4; printf ( “pi = %f\n”, pi); return 0; } 4.1.1 程序解析-求π的近似值 pi = 3.141613 item=0.0 ? fabs(item) < 0.0001
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有