Advertisement
Misha_

filter

Dec 3rd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #define SZ 100
  4.  
  5. int filter(int*,int,int*);
  6. bool check(int);
  7.  
  8. int main() {
  9.     int data[SZ] = {0}, n = 0, res[SZ] = {0}, m = 0;
  10.     scanf("%d", &n);
  11.     for (int i = 0; i < n; ++i)
  12.         scanf("%d", &data[i]);
  13.     m = filter(data, n, res);
  14.     printf("%d\n", m);
  15.     for (int i = 0; i < m; ++i)
  16.         printf("%d ", res[i]);
  17.     return 0;
  18. }
  19.  
  20. int filter(int *data, int n, int *res) {
  21.     int m = 0;
  22.     for (int i = 0 ; i < n; ++i)
  23.         if (check(data[i]))
  24.             res[m++] = data[i];
  25.     return m;
  26. }
  27.  
  28. bool check(int a) {
  29.     return (a % 2 == 0);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement