Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. long double modul(long double a)
  4. {
  5. if (a < 0)
  6. {
  7. return -a;
  8. }
  9. else
  10. {
  11. return a;
  12. }
  13. }
  14. long double ploshad_treugolnika(long XA, long YA, long XB, long YB, long XC, long YC)
  15. {
  16. long double S = modul((XB - XA) * (YC - YA) - (XC - XA) * (YB - YA))/2;
  17. return S;
  18. }
  19. void function(long* array, long size) {
  20. long double SUM = 0;
  21. for (long i = 5; i < size; i += 2) {
  22. long double S = ploshad_treugolnika(array[0], array[1], array[i - 3], array[i - 2], array[i - 1], array[i]);
  23. SUM = (SUM + S);
  24. }
  25. printf("%3.10Lg", SUM);
  26. }
  27. int main()
  28. {
  29. long N, x, y;
  30. scanf("%ld", &N);
  31. long* pa;
  32. pa = (long*)malloc(2 * N * sizeof(long));
  33. for (int q = 0; q < 2 * N; q += 2) {
  34. scanf("%ld%ld", &x, &y);
  35. pa[q] = x;
  36. pa[q + 1] = y;
  37. }
  38. function(pa, 2 * N);
  39. free(pa);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement