Advertisement
LordMZTE

Untitled

Jun 4th, 2023
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. int find_outlier(const int* values, size_t count) {
  4.     int last_even, last_odd;
  5.     int n_even, n_odd;
  6.     last_even = last_odd = n_even = n_odd = 0;
  7.  
  8.     for (size_t i = 0; i < count; i++) {
  9.         if (values[i] % 2 == 0) {
  10.             last_even = values[i];
  11.             n_even++;
  12.         } else {
  13.             last_odd = values[i];
  14.             n_odd++;
  15.         }
  16.     }
  17.  
  18.     return n_even > n_odd ? last_odd : last_even;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement