Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #define NMAX 100
- void delete(int arr[], int *n, int pos) {
- for (int i = pos; i < *n - 1; i++) {
- arr[i] = arr[i + 1];
- }
- (*n)--;
- }
- void filter(int arr[], int *n, bool (*cond)(int)) {
- for (int i = 0; i < *n; i++) {
- if (!cond(arr[i])) {
- delete(arr, n, i--);
- }
- }
- }
- bool cond(int x) {
- return x < 0;
- }
- int main(void) {
- int n;
- scanf("%d", &n);
- static int arr[NMAX];
- for (int i = 0; i < n; i++) {
- scanf("%d", arr + i);
- }
- filter(arr, &n, cond);
- for (int i = 0; i < n; i++) {
- printf("%d ", arr[i]);
- }
- puts("");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement