⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpi.c

📁 串行程序,用来计算pi值,可与并行程序进行比较
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -