Advertisement
hurmawe

max_even

Dec 18th, 2022
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <malloc.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main()
  6. {
  7.    
  8.     int n, number_even = 0, pos_max = 0;
  9.     scanf("%d", &n);
  10.     int* mas;
  11.     mas = (int*)  malloc(n * sizeof(int));
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         scanf("%d",  &mas[i]);
  15.     }
  16.    
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         if (mas[i] % 2 == 0)
  20.         {
  21.             number_even++;
  22.             if (mas[i] > mas[pos_max])
  23.             {
  24.                 pos_max = i;
  25.             }
  26.         }
  27.     }
  28.  
  29.     n++;
  30.     mas = realloc(mas, n * sizeof(int));
  31.     mas[n-1] = number_even;
  32.    
  33.     int buff = mas[pos_max + 1];
  34.     mas[pos_max+ 1] = mas[n-1];
  35.     mas[n-1] = buff;
  36.    
  37.     for (int i = 0; i < n; i++)
  38.     {
  39.         printf("%d ",mas[i]);
  40.     }
  41.     free(mas);
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement