PI算法

// Cyclotomic.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include 
#include 
#include 
#include 

using namespace std;


void Cyclotomic(int n)
{
	int i, s;
	double k, len;
	i = 0;
	k = 3.0;
	len = 1.0;
	s= 6;
	while(i <= n)
	{
		printf("第%2d次切割,为正%5d边形,PI=%24f\n", i, s, k*sqrt(len));
		s *= 2;
		len = 2 - sqrt(4 - len);
		i++;
		k *= 2.0;
	}
}


int main(int argc, char* argv[])
{
	int n;
	printf("输入切割圆次数: !\n");
	scanf("%d", &n);
	Cyclotomic(n);
	return 0;
}



你可能感兴趣的:(C)