cpi.c

来自「串行程序,用来计算pi值,可与并行程序进行比较」· C语言 代码 · 共 29 行

C
29
字号
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

void main(int argc, char *argv[])
{
	int		NumIntervals	= 0;	//num intervals in the domain [0,1] of F(x)= 4 / (1 + x*x)
	double	IntervalWidth	= 0.0;	//width of intervals
	double  IntervalLength  = 0.0;	//length of intervals
	double	IntrvlMidPoint	= 0.0;	//x mid point of interval
	int		Interval		= 0;	//loop counter
	int		done			= 0;	//flag
	double	MyPI			= 0.0;	//storage for PI approximation results
	double	ReferencePI		= 3.141592653589793238462643; //ref value of PI for comparison
	
	while (!done) //loops until done == 0
	{
		IntervalLength = 0.0;
		printf("\nEnter the number of intervals: (0 quits) ");fflush(stdout);
		scanf_s("%d",&NumIntervals);
	
		if (NumIntervals == 0)
			done = 1;   //exit if number of intervals = 0  
		else
		{
			//ADD CODE TO APPROXIMATE PI HERE
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?