Saturday 19 March 2016

Descending Order Check


Write a program to find whether the given array is sorted in descending order.

Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.

Output Format: 
Print yes if the array is sorted in descending order. Print no if the array is not sorted in descending order.

Sample Input 1: 
 5
 2
 3
 6
 8
 1
 Sample Output 1: 
 no

Sample Input 2: 
 5
 20
 13
 6
 4
 1

 Sample Output 2: 
 yes

Code
  #include<stdio.h>
int main(){
  int a[15],i,flag=1;
  int n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    if(i>0)
    {
      if(!(a[i-1]>a[i]))
        flag=0;
    }
  }
  if(flag)
    printf("yes");
  else 
    printf("no");
  return 0;
}
      

4 comments:

  1. post for ascendind order please

    ReplyDelete
  2. This is a really good read for me. Must agree that you are one of the coolest blogger I ever saw. Thanks for posting this useful information. This was just what I was on looking for. I'll come back to this blog for sure!
    how to care for an orchid

    ReplyDelete
  3. It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. Buy Views on YouTube cheap

    ReplyDelete