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

円周率を求める。
演習で求める。
ソースは↓に。

結果

result.log
---START---     22:23:56
r弱=2305843009213693952.000000

正解↓
3.141592653589793115997963
3.132264619271114547416346,1022:23:56
3.141592652478686797934415,41101022:28:56
3.141592652926463724583073,58129022:33:56
3.141592653100025778201143,71164022:38:56

15分で
3.141592653
まで正解。
ちょっと放置しとく。

↓放置した結果

結果が入る予定

code

pai21.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <float.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[])
{
	printf("---START---     ");	now();//時刻表示
	//--- --- --- ---
	const double r= sqrtl(sqrtl(sqrtl(sqrtl(DBL_MAX))))/4.0d /2.0d;
	printf("r弱=%lf\n\n",r);
	printf("正解↓\n%1.24lf\n",M_PI );

	unsigned long waris = 10 ,m=100 ,o=0,nnn;

	double x,y ,xx,yy;
	double oy ,ox,een;
	do{
		y=0.0d;
		oy=0.0d;
		ox=r;
		een=0.0d;
		char ff = 0 ;
		while( !ff )
		{
			y += r/waris ;
			ff = y > r;
			if(ff ) y = r ;
			
			x = sqrtl( r*r - y*y);
			xx = ox - x;
			yy = y -oy ;
			ox = x ;
			oy = y ;
			een += sqrtl(yy*yy +xx*xx);
//			printf("y=%lf %lf\n",y,een);
		}

		nnn = time(NULL);
		if ( nnn >= o)
		{
			o = nnn + 60*5  ;
			printf("%1.24lf,%d",een/r*2.0d,waris );
			now();
		}
		waris += 10 ;
		m--;
		m=1;
	}while(m);


	return 0;
}
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?