#include #include #include #include #define randomize() srand((unsigned)time(NULL)) // ³­¼ö ¹ß»ý±â ÃʱâÈ­ #define random(n) (rand() % (n)) //0~n±îÁöÀÇ ³­¼ö ¹ß»ý #define OK 1 #define NO 2 int incircle(int ax, int ay,int r) { int x = ax , y = ay - r; int value = (x*x + y*y); if (value <= r*r) { return OK; } else { return NO; } } void calc(HDC hdc) { int num = 45000;//¸î°³ ·£´ý ¹ß»ý ½Ãų·¡? int incount = 0;//¿ø ¾È¿¡ µé¾î°£ Á¡ÀÇ ¼ö int* pos_x;//xÁÂÇ¥ int* pos_y;//yÁÂÇ¥ int i;//·çÇÁ º¯¼ö float pi;//°á°ú°ª pi char str[100]; //µ¿Àû ÇÒ´ç pos_x = (int*)malloc(sizeof(int) * num); pos_y = (int*)malloc(sizeof(int) * num); for(i = 0 ; i < num ; i++) { pos_x[i] = random(500);//Á¡ ÂïÀ½ pos_y[i] = random(500); if(incircle(pos_x[i],pos_y[i],500) == OK)//¾È¿¡ µé¾î °¡ ÀÖ´ÂÁö È®ÀÎ { incount++;//µé¾î°¡ ÀÖÀ¸¸é Ä«¿îÆ® Ãß°¡ SetPixel(hdc,10+pos_x[i],10+pos_y[i],RGB(255,0,0)); } else { SetPixel(hdc,10+pos_x[i],10+pos_y[i],RGB(0,0,0)); } } pi = (float)incount / num * 4;//ÆÄÀÌ °è»ê sprintf(str,"TestCase : %d, pi = %f",num,pi); TextOut(hdc,0,550,TEXT(str),lstrlen(str)); }