Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5.  
  6. double random(double val1, double val2){
  7. return (double)rand() / RAND_MAX * (val2 - val1) + val1;
  8. }
  9.  
  10. double value(double x){
  11. return x * x;
  12. }
  13.  
  14. int increasing(double x, double y){
  15. if(y > 0 && y <= value(x)) return 1;
  16. if(y < 0 && y >= value(x)) return -1;
  17. return 0;
  18. }
  19.  
  20. int main(void) {
  21. srand(time(NULL));
  22. int xp, xk, yp, yk;
  23. int n;
  24. scanf("%d%d%d%d%d", &xp, &xk, &yp, &yk, &n);
  25. double poleProstokata = abs(xk - xp) * abs(yk - yp);
  26. int c = 0;
  27. int licznik = n;
  28. while(licznik--){
  29. double x = random(xp, xk);
  30. double y = random(yp, yk);
  31. c += increasing(x, y);
  32. }
  33. double calka = poleProstokata * c / n;
  34. printf("%f", calka);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement