C Program to check whether array is sorted or not using recursion

Simple C program to check whether array is sorted or not using recursion. This is a simple C program using recursion. If array is sorted then it will print that array is sorted otherwise it will print array is not sorted.
#include<stdio.h>
/* n=size of array-1 */
int CheckSortedArray(int arr[],int n)
{
	if(n==0)
	return 1;
	return (arr[n]<arr[n-1])?0:CheckSortedArray(arr,n-1);
}
int main()
{
	int arr[6]={10,22,37,54,75,96};
	/* size of array =6 */
	int j=CheckSortedArray(arr,5);
	if(j==1)
	{
		printf("Array is sorted\n");
	}
	else
	{
		printf("Array is not sorted\n");
	}
	return 0;
}



Popular posts from this blog