constk

Lab6_Task2

Nov 27th, 2019
209
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdio.h"
  3. #include <iostream>
  4.  
  5. int main() {
  6. setlocale(0, "Russian");
  7.  
  8. const int N = 5;
  9. short A[N] = {100, 80, 90, 2, 5}, i = 0, n, sum = 0;
  10. float average = 0;
  11.  
  12. for (i = 0; i < N; i++) {
  13. printf("A[%d] = %hd\n", i, A[i]);
  14. // scanf("%hd", &A[i]);
  15. sum += A[i];
  16. }
  17. puts("");
  18.  
  19. average = (float)sum / N;
  20. printf("\nСреднее значение = %2.2f\n", average);
  21. //n = N - 1;
  22. n = N;
  23.  
  24. /*while (i <= n) {
  25. if (A[i] < average) {
  26. A[i] = A[n];
  27. A[n] = 0;
  28. n--;
  29. }
  30. else
  31. i++;
  32. }*/
  33.  
  34. for (int i = 0; i < n;) {
  35. if (A[i] < average) {
  36. for (int j = i; j < (n - 1); j++) {
  37. A[j] = A[j + 1];
  38. }
  39. A[n - 1] = 0;
  40. n--;
  41. }
  42. else
  43. i++;
  44. }
  45.  
  46. for (int i = 0; i < N; i++) {
  47. printf("%hd ", A[i]);
  48. }
  49.  
  50. system("pause");
  51. return 0;
  52. }
RAW Paste Data