Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. double max(double a, double b) {
  7. if(a < b) return b;
  8. return a;
  9. }
  10.  
  11. int main() {
  12. double val[41];
  13. double cur_value = -8;
  14. for(int i = 0; i < 41; i ++)
  15. {
  16. val[i] = sin(cur_value*0.6) * 5.0;
  17. cur_value += 0.4;
  18. }
  19. double maximum = -5.0, sum = 0, cnt = 0;
  20. for(int i = 0; i < 41; i ++)
  21. {
  22. maximum = max(maximum, val[i]);
  23. if(val[i] < 0.0)
  24. {
  25. sum += val[i];
  26. cnt++;
  27. }
  28. }
  29. printf("%.6f\n%.6f\n", maximum, sum/cnt);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement