I don’t want to do your homework for you. However, I know that it sometimes helps to see a working example. This is a really super rudimentary example, but it should help you to understand the logic behind such a problem.
Please study this answer, rather than just submitting it as correct. You will only gain insight by learning.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
const int asc = 1;
const int desc = 0;
int array_asc[11] = {1,2,3,4,5,6,7,8,9,10};
int array_desc[11] = {10,9,8,7,6,5,4,3,2,1};
int array_rand[11] = {7,3,8,4,5,1,6,2,4,4};
int order_check[2] = {0, 0};
int check_order(int* array){
if(array[0] < (array[1])){
order_check[0] = asc;
} else if (array[1] < (array[0])){
order_check[0] = desc;
} else {
return 1;
}
return 0;
}
int check_array(int* array, int* check){
switch(check[0]){
case 1:
for(int i = array[0]; i < array[9]; i ++){
if(array[i] < (array[i+1])){
continue;
} else {
return i + 1;
}
}; break;
case 0:
for(int i = 0; i < 9; i++){
if(array[i] > (array[i+1])){
continue;
} else {
return i + 1;
}
}; break;
}
return 0;
}
int main(int argc, char** argv) {
int ret;
if(check_order(array_rand) == 0){
if(ret = check_array(array_rand, order_check)){
printf("Order breaks at index %d", ret);
} else {
printf("Array is in perfect order");
}
} else {
printf("Array is not in order.\n");
}
return (EXIT_SUCCESS);
}
solved Function in C language. + Arrays [closed]