[ create a new paste ] login | about

Link: http://codepad.org/eyLxAOFV    [ raw code | output | fork ]

C++, pasted on Dec 10:
#include <stdio.h> 
#include <math.h> 
#define N (6) 
namespace shukudai{
struct complex { 
	double re;
	double im; 
	complex(double a,double b){
		re=a;
		im=b;
	}
}; 

}
double Distance(struct shukudai::complex c0, struct shukudai::complex c1) { 
	return sqrt((c0.re-c1.re)*(c0.re-c1.re)+(c0.im-c1.im)*(c0.im-c1.im)); 
} 
int main(void) { 
	int i; 
	double PI = 3.1415926535897931;
	double sum = 0; 
	for (i=0 ; i<N ; i++){
		int j = (i+1) % N;
		sum += Distance(
			shukudai::complex(cos(2*PI*i/N),sin(2*PI*i/N)),
			shukudai::complex(cos(2*PI*j/N),sin(2*PI*j/N))
		); 
	}
	printf("%f\n",sum); 
	return 0; 
} 


Output:
1
6.000000


Create a new paste based on this one


Comments: