Line 2: |
Line 2: |
| === The Problem and the Code === | | === The Problem and the Code === |
| | | |
| + | <nowiki>#include <stdio.h></nowiki><br> |
| + | <nowiki>#include <stdlib.h></nowiki><br> |
| + | <nowiki>#include <time.h></nowiki><br> |
| | | |
| + | int main(int argc, char *argv[])<br> |
| + | <nowiki>{</nowiki><br> |
| + | <nowiki>int i,N,incirc=0;</nowiki><br> |
| + | <nowiki>double x,y,circrad2;</nowiki><br> |
| + | |
| + | <nowiki>sscanf(argv[1], "%d", &N); // get iteration number from input</nowiki><br> |
| + | <nowiki>srand(time(NULL)); // seed random number generator</nowiki><br> |
| + | |
| + | <nowiki>circrad2=1.0*RAND_MAX; </nowiki><br> |
| + | <nowiki>circrad2*=circrad2; // Define radius squared </nowiki><br> |
| + | |
| + | <nowiki>for(i=0;i<N;i++){</nowiki><br> |
| + | <nowiki>x=1.0*rand(); y=1.0*rand(); // get rand. point and</nowiki><br> |
| + | <nowiki>incirc += (x*x+y*y) < circrad2; // check if inside circle</nowiki><br> |
| + | } <br> |
| + | |
| + | <nowiki>printf("pi=%.12f\n",4.0*incirc/N); // display probability</nowiki><br> |
| + | return 0;<br> |
| + | } |
| === Preparation for Job Submission === | | === Preparation for Job Submission === |
| | | |
| === Job Submission and Management === | | === Job Submission and Management === |
| + | |
| == R example == | | == R example == |
| === The Problem and the Code === | | === The Problem and the Code === |