Sorted Order Check in C Programming

Image result for c programming
Sorted Order Check in C Programming
Code:
  #include<stdio.h>
int main(){
  int a[15],n,i,aflag=0,bflag=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    if(i>0){
      if((a[i-1]>a[i]))
        aflag++;
      else
        bflag++;
    }
  }
  if(aflag==(n-1)||(bflag==(n-1)))
    printf("yes");
  else
    printf("no");
  return 0;
}

No comments