-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortedornot.c
52 lines (50 loc) · 1.2 KB
/
sortedornot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Program to determine whether th given array is in ascendng
// or descending order | Vishruth Codes
#include<stdio.h>
void ascordesc(int ar[],int n)
{
int i=2,count;
//comparing frst two elements to decide ascending or not.
if(ar[0]<ar[1])
{
int count=0;
while(i<n)
{
if(ar[i-1]>ar[i])
{
printf("\nThe array is unsorted starting from %d.", ar[i]);
count++;
}
i++;
}
if(count==0)
{
printf("\nThe array sorted and is in ascending order.");
}
}
else if(ar[0]>ar[1])
{
count=0;
while(i<n)
{
if(ar[i-1]<ar[i])
{
printf("\nThe array is unsorted starting from %d.", ar[i]);
count++;
}
i++;
}
if(count==0)
{
printf("\nThe array sorted and is in descending order.");
}
}
}
int main()
{
int ar[10]={11,12,13,14,15,16,7,18,19,20};
int n=10;//length of the array
printf("\nThe array is: 11,12,13,14,15,16,7,18,19,20");
ascordesc(ar,n);
return 0;
}