Write a recursive function that returns 1 if an array of size n is in sorted order and 0 otherwise. Note: If array a stores 3, 6, 7, 7, 12, then isSorted(a, 5) should return 1 . If array b stores 3, 4, 9, 8, then isSorted(b, 4) should return 0.int isSorted(int *array, int n){

Respuesta :

Answer:

Here the code is given as follows,

Explanation:

Code:-

#include <stdio.h>  

int isSorted(int *array, int n) {

   if (n <= 1) {

       return 1;

   } else {

       return isSorted(array, n-1) && array[n-2] <= array[n-1];

   }

}  

int main() {

   int arr1[] = {3, 6, 7, 7, 12}, size1 = 5;

   int arr2[] = {3, 4, 9, 8}, size2 = 4;  

   printf("%d\n", isSorted(arr1, size1));

   printf("%d\n", isSorted(arr2, size2));

   return 0;

}

Output:-

Ver imagen tallinn