Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define ZERO 0
  4. #define BAD 1
  5. int vvod(int *a, int *n)
  6. {
  7. char sp = ' ';
  8. int ch_s = 0;
  9. int ch;
  10. int i = 0;
  11. scanf("%d", n);
  12. if ((*n == 0) || (*n > 10))
  13. return BAD;
  14. else
  15. {
  16. while (i < *n && sp != '\n')
  17. {
  18. ch = scanf("%d%c", &a[i], &sp);
  19. if (sp != '\n' && ch != EOF)
  20. ch_s ++;
  21. i++;
  22. }
  23. if (ch_s != (*n) - 1)
  24. return BAD;
  25. else
  26. return ZERO;
  27. }
  28. }
  29. float srednee(int *a, int n)
  30. {
  31. float x = 1;
  32. float mg;
  33. int i;
  34. float power;
  35. float positiv_n = 0;
  36. for (i = 0; i < n; i++)
  37. {
  38. if (a[i] >= 0)
  39. {
  40. x = x * a[i];
  41. positiv_n += 1;
  42. }
  43. }
  44. if (positiv_n == 0)
  45. mg = -1;
  46. else
  47. {
  48. power = 1 / positiv_n;
  49. mg = pow(x, power);
  50. }
  51. return mg;
  52. }
  53. int main()
  54. {
  55. int a[10];
  56. int n;
  57. int x;
  58. float res;
  59. x = vvod(a, &n);
  60. res = srednee(a, n);
  61. if (x == 1)
  62. return BAD;
  63. else if (res < 0)
  64. return BAD;
  65. else
  66. {
  67. printf("%f", res);
  68. return ZERO;
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement