📄 cpi.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 + -