Untitled
unknown
plain_text
3 years ago
709 B
10
Indexable
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main() {
const double r=9;
int i, m, n,itr=0;
double x,y,z,pi;
int arr[1]={0,1};
printf("Enter the number of iterations you want= ");
scanf("%d", &n);
int count= 0;
for(i = 0; i < n; ++i) {
x = ((double)rand() / (RAND_MAX)) *r;
y = ((double)rand() / (RAND_MAX))*r;
z = x * x + y * y;
double distance= sqrt(z);
if( distance <=r )
{
itr++;
count++;
printf("%d %lf %lf %lf %d",itr,x,y,distance,count);
printf("\n");
}
else{
itr++;
printf("%d %lf %lf %lf %d",itr,x,y,distance,count);
printf("\n");
}
}
pi= (double) (4*count)/itr;
printf("\n%lf",pi);
return(0);
}Editor is loading...