kirya_shkolnik

Давид 4 задача

Mar 24th, 2022 (edited)
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. double finder(double a, double b, double h1, double c, double d, double h2, double& count){
  7.     int n1 =  int((b + h1/2. - a)/h1) + 1;
  8.     int n2 =  int((d + h2/2. - c)/h2) + 1;
  9.     count = 0;
  10.     double sum = 0;
  11.     double x, y, z;
  12.     for(int i=1; i<n1; ++i){
  13.         x = a + (i-1) * h1;
  14.         for(int j=1; j<n2; ++j){
  15.             y = c + (j-1) * h2;
  16.             z = y - (0.1*sin(x)/2);
  17.             if(z < 0){
  18.                 count++;
  19.                 sum+=z;
  20.             }
  21.         }
  22.     }
  23.     return sum;
  24. }
  25.  
  26. int main(){
  27.     double a,  b,  h1,  c,  d,  h2, count, sum;
  28.     cin >> a >>  b >>  h1 >>  c >>  d >>  h2;
  29.     sum = finder(a,  b,  h1,  c,  d,  h2, count);
  30.     cout << sum << endl << count;
  31. }
Add Comment
Please, Sign In to add comment