Untitled
unknown
plain_text
a year ago
709 B
1
Indexable
Never
#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); }