fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. double sum(int c, int v[]) {
  6. double acc = 0.0;
  7. for (int i = 0; i < c; i++) {
  8. acc += v[i];
  9. }
  10. return acc;
  11. }
  12.  
  13. bool* pseudo_map(int c, int v[]){
  14. bool* array = (bool *)malloc(sizeof(bool) * c);
  15. double avg = sum(c, v) / c;
  16. for (int i = 0; i < c; i++) {
  17. array[i] = v[i] >= avg ? true : false;
  18. }
  19. return array;
  20. }
  21.  
  22. int count(int c, bool array[]) {
  23. int acc = 0;
  24. for (int i = 0; i < c; i++) {
  25. if (array[i]) {
  26. acc++;
  27. }
  28. }
  29. return acc;
  30. }
  31.  
  32. int main(void) {
  33. char a[5];
  34. printf("n: ");
  35. scanf("%4s%*[^\n]", a);
  36. int n = strtod(a, NULL);
  37. int* p = (int *)malloc(sizeof(int) * n);
  38. for (int i = 0; i < n; i++) {
  39. printf("? ");
  40. scanf("%4s%*[^\n]", a);
  41. p[i] = strtod(a, NULL);
  42. }
  43. printf("%d\n", count(n, pseudo_map(n, p)));
  44. free(p);
  45. return EXIT_SUCCESS;
  46. }
  47.  
Success #stdin #stdout 0.01s 5464KB
stdin
Standard input is empty
stdout
n: 0