Advertisement
dancidenis

lab7p1

Nov 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int isSorted(unsigned t[], int n)
  4. {
  5.     int i, type;
  6.     if(t[0]<=t[1]) type=0;
  7.         else type=1;
  8.     for(i=1; i<n-1; i++)
  9.     {
  10.         if((type==0) && !(t[i]<=t[i+1]))
  11.             return 0;
  12.         if((type==1) && !(t[i]>=t[i+1]))
  13.             return 0;
  14.     }
  15.     return 1;
  16.  
  17. }
  18.  
  19. #define n 5
  20.  
  21. int main()
  22. {
  23.     unsigned t[n]={1, 3, 5, 7, 9};
  24.     printf("%d", isSorted(t, n));
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement