Question

points are chosen Uniformly at random within-/revnit sgua? tb esthmaste expectd (vema 1e ? .nu segment joinin5 ?uch ufo) ntS ints, in ont Stvare and Co mpute oistanca. do it maty tmes and hen

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<iomanip>
#include<math.h>

using namespace std;

int main(){

   srand(time(NULL));
   cout << "Enter number of times to generate 2 points:";
   int n;
   cin >> n;
   double sum = 0;
   for (int i = 0; i<n; i++){
      double x1 = ((double)rand() / (RAND_MAX));
      double y1 = ((double)rand() / (RAND_MAX));
      double x2 = ((double)rand() / (RAND_MAX));
      double y2 = ((double)rand() / (RAND_MAX));
      double d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
      sum = sum + d;
   }
   cout << "The average distance is " << fixed << setprecision(2) << sum/(double)n << endl;
}

Add a comment
Know the answer?
Add Answer to:
points are chosen Uniformly at random within-/revnit sgua? tb esthmaste expectd (vema 1e ? .nu segment...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT