Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- double random(double val1, double val2){
- return (double)rand() / RAND_MAX * (val2 - val1) + val1;
- }
- double value(double x){
- return x * x;
- }
- int increasing(double x, double y){
- if(y > 0 && y <= value(x)) return 1;
- if(y < 0 && y >= value(x)) return -1;
- return 0;
- }
- int main(void) {
- srand(time(NULL));
- int xp, xk, yp, yk;
- int n;
- scanf("%d%d%d%d%d", &xp, &xk, &yp, &yk, &n);
- double poleProstokata = abs(xk - xp) * abs(yk - yp);
- int c = 0;
- int licznik = n;
- while(licznik--){
- double x = random(xp, xk);
- double y = random(yp, yk);
- c += increasing(x, y);
- }
- double calka = poleProstokata * c / n;
- printf("%f", calka);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement