0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

円周率近似。 多角形の数を追記増やしていく方式

Posted at

まず、結論。

Googleスプレットシートの方が有効桁数が多かった

だけど、まずはCプログラム↓

pai13.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>


void now(void)
{
	time_t t = time(NULL);
	struct tm *local = localtime(&t);
/*
	printf("%04d/", local->tm_year + 1900);
	printf("%02d/", local->tm_mon + 1);
	printf("%02d", local->tm_mday);

	printf(" ");
*/
	printf("%02d:", local->tm_hour);
	printf("%02d:", local->tm_min);
	printf("%02d\n", local->tm_sec);
	fflush(stdout);
}

int main(int argc,char *argv[])
{
	unsigned long long	nnn = time(NULL),o=0;
	unsigned long long	n=1000;
	if(argc > 1 )
	{
		n=atol( argv[1] ) ;
	}
	printf("---START---     ");	now();//時刻表示
	//--- --- --- ---
	int m=10 ; // 計算する数

	double ox,oy  ,x,y ,hiriz ,a ,kos;
	ox = 1.0d /sqrtf(2.0d);
	oy = ox ;
	kos = 8.0d ;

	while(m)
	{
		x=1.0d-(1.0d-ox) / 2.0d;
		y=oy / 2.0d;

		hiriz = 1/sqrtf(x*x +y*y);
		x *= hiriz ;
		y *= hiriz ;
		a=sqrt((1-x)*(1-x) + y*y);

		ox = x ;
		oy = y ;

		nnn = time(NULL);
//		if ( nnn >= o)
		{
			printf("%1.24f ,%d角形\n",a * kos,(long long)kos ) ;
//			now();
			o = nnn + 1 *1  ;
			m--;
		}

		kos *= 2.0d;
//m=1;	
	}//...while
	printf("\n正解π↓\n%1.24f \n",M_PI ) ;
	 
	 
	return 0;
}
結果.txt
---START---     18:23:18
3.121445215682374652033104 ,8角形
3.136548472039406565414765 ,16角形
3.140331117647078507104652 ,32角形
3.141277270129558374378576 ,64角形
3.141513802258355525509614 ,128角形
3.141572989680802230338941 ,256角形
3.141587814405001566342435 ,512角形
3.141591629083641201702903 ,1024角形
3.141592637263832532568131 ,2048角形
3.141593029342560683403462 ,4096角形

正解π↓
3.141592653589793115997963 


3.1415926
まで正解


Googleスプレットシートは

..
3.141592653589790000000000


3.14159265358979
まで正解。

Googleすげぇや
(あんたが15年前のPC使ってるからだよ)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?