Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,846 questions

51,767 answers

573 users

How to check if a value of each int array element is equal or greater than the previous element in C

1 Answer

0 votes
#include<stdio.h>

int check(int arr[], int arr_size) {
    for (int i = 0; i < arr_size - 1; i++) {
         if (arr[i + 1] < arr[i]) return 0;
    }
    return 1;
}

int main() 
{
    int arr1[] = {2, 3, 3, 7, 7, 9};
    int arr_size = sizeof(arr1)/sizeof(arr1[0]);
    printf("%d\n",check(arr1, arr_size));
    
    int arr2[] = {3, 3, 1, 1, 1};
    arr_size = sizeof(arr2)/sizeof(arr2[0]);
    printf("%d\n",check(arr2, arr_size));

    return 0;
}


/*
run:

1
0

*/

 



answered Mar 30, 2019 by avibootz
...