How to check if an array is not increasing in C

1 Answer

0 votes
#include <stdio.h>
#include <stdbool.h>
 
bool not_increasing(int arr[], int size) {
    for (int i = 0; i < size - 1; i++) {
        if (arr[i] < arr[i + 1]) {
            return false;
        }
    }
     
    return true;
}
 
int main() {
    int arr[] = {89, 70, 44, 32, 25, 19, 18, 7, 5, 3, 1};
    int size = sizeof(arr) / sizeof(arr[0]);
     
    printf("%s\n", not_increasing(arr, size) ? "true" : "false");
     
    return 0;
}
 
 
 
 
/*
run:
 
true
 
*/

 



answered Feb 26, 2024 by avibootz
edited Feb 26, 2024 by avibootz
...