/* 14(b) W.A.P. to accept n elements and check whether or not they are sorted. */

#include<stdio.h>
void main()
{
    int i,n,*a,j; /* Variable Declarations */
    clrscr();
    printf("\nEnter the number of elements in the array : ");
    scanf("%d",&n);
    printf("\nEnter %d elements in the array as follows :\n",n);
    for (i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    i=0;
    j=0;
    /* Check whether the given list is sorted in ascending order */
    while (i<(n-1))
    {
        if (a[i]<a[i+1])
        {
            ++j;
        }
        i++;
    }
    if (j==(n-1))
    {
        printf("\nElements are in ascending order\n");
        getch();
        exit(0);
    }
    i=0;
    j=0;
    /* Check whether the given list is sorted in descending order */
    while (i<(n-1))
    {
        if (a[i]>a[i+1]) ++j;
        i++;
    }
    if (j==(n-1))
    {
        printf("\nElements are in descending order\n");
        getch();
        exit(0);
    }
    printf("\nElements are unsorted"); /* Given list or vector is not sorted */
    getch();
    return 0;
}