random numbers

Area of circle using Random numbers
/* Author Somenath Jalal, Hooghly Women's College'*//* Date: 09 Dec, 2017 */
#include <stdio.h> #include <math.h> #include <stdlib.h> main() { int i,counts; float x,y,area; int nmax=1000; /* Generate Nmax number of random numbers*/ int a=1; int b=nmax; FILE *f1=fopen("data-circle-random.dat","w"); counts=0; for(i=1;i<=nmax;i++) /* Generate Nmax number of random numbers*/ { /* start of for loop*/ x=(rand()%b + a)/(1.0*b); /* this will give random number [0,1]*/ y=(rand()%b + a)/(1.0*b); /* this will give random number [0,1]*/ printf("%f %f\n",x,y); fprintf(f1,"%f %f \n",x,y); if(x*x+y*y <= 1.0) { counts = counts +1; } } /*end of for loop*/ area = counts*4.0/nmax ; printf("Area of Circle = %f\n",area); return(0); } /* end of main program*/