Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following C function: int ascending(int * middle int * last) Which ret

ID: 3822665 • Letter: W

Question

Write the following C function: int ascending(int * middle int * last) Which returns whether an integer array is sorted or not (in ascending order). Assume that the length of the array is always odd; middle is a pointer pointing to the middle element and last is a pointer pointing to the last element of the array. If the array is sorted in ascending order the function will return l: otherwise it will return 0. b) Write the main function (declare an integer array A consisting of 11 positive integers), which using the above function will print the following: A is/is not sorted in ascending order. The first half of A is/is not sorted in ascending order. The second half of A is/is not sorted in ascending order. It should correctly print whether the arrays and subarrays are sorted or not.

Explanation / Answer

1. To Check Whether The Array Is Sorted in Ascending or Descending

void func1{

for( a = 0 ; a < no ; a++ )

{
scanf("%d",&arr[a]);
}
for( a = 0 ; a < no - 1 ; a++ )
{
if( arr[a] < arr[a+1] )
{
k++;
break;
}
}

}

Hence, this is the code as you have asked and it is completely operable.

2. To Write A Main Function For Above Work

void Srting_arr(int arr[], int no) {
int a;
// Descending Order Check
for (a=1;a<no;++a) {
if (arr[a]<arr[a-1]) {
break;
}
}
if ( a < no ) {   // Failed Descending Order Check
for (a=1;a<no;++a) //Ascending order check
if (arr[a]>arr[a-1]) {
break;
}
}
if ( a < no ) {
printf("The given array is not sorted o");
}
else {
printf("Array is sorted in descending o");
}
}
else {
printf("Array is sorted in ascending o");
}
}

Hope it helps...