Advertisement
STANAANDREY

filter c

Feb 21st, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4.  
  5. void printOk(int arr[], int n, bool (*f)(int)) {
  6.   for (int i = 0; i < n; i++) {
  7.     if (f(arr[i])) {
  8.       printf("%d: %d\n", i, arr[i]);
  9.     }
  10.   }
  11. }
  12.  
  13. bool isOdd(int x) {
  14.   return x & 1;
  15. }
  16.  
  17. int main(void) {
  18.   int n;
  19.   scanf("%d", &n);
  20.   int *arr = calloc(sizeof(int), n);
  21.   for (int i = 0; i < n; i++) {
  22.     scanf("%d", arr + i);
  23.   }
  24.   printOk(arr, n, isOdd);
  25.   return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement