1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> int main(void) { srand(time(NULL)); int niter, inside_dots = 0; double x, y, z, pi; printf("¹Ýº¹È½¼ö: "); scanf("%d", &niter); inside_dots = 0; for (int i = 0; i < niter; i++) { x = (double)rand() / RAND_MAX; y = (double)rand() / RAND_MAX; z = x * x + y * y; if (z <= 1) inside_dots++; } pi = (double)inside_dots / niter * 4; printf("ÆÄÀÌ = %lf\n\n", pi); return(0); } | cs |