Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define ZERO 0
- #define BAD 1
- int vvod(int *a, int *n)
- {
- char sp = ' ';
- int ch_s = 0;
- int ch;
- int i = 0;
- scanf("%d", n);
- if ((*n == 0) || (*n > 10))
- return BAD;
- else
- {
- while (i < *n && sp != '\n')
- {
- ch = scanf("%d%c", &a[i], &sp);
- if (sp != '\n' && ch != EOF)
- ch_s ++;
- i++;
- }
- if (ch_s != (*n) - 1)
- return BAD;
- else
- return ZERO;
- }
- }
- float srednee(int *a, int n)
- {
- float x = 1;
- float mg;
- int i;
- float power;
- float positiv_n = 0;
- for (i = 0; i < n; i++)
- {
- if (a[i] >= 0)
- {
- x = x * a[i];
- positiv_n += 1;
- }
- }
- if (positiv_n == 0)
- mg = -1;
- else
- {
- power = 1 / positiv_n;
- mg = pow(x, power);
- }
- return mg;
- }
- int main()
- {
- int a[10];
- int n;
- int x;
- float res;
- x = vvod(a, &n);
- res = srednee(a, n);
- if (x == 1)
- return BAD;
- else if (res < 0)
- return BAD;
- else
- {
- printf("%f", res);
- return ZERO;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement