Advertisement
ppupil2

Q2.2-PRF192-PE-trial

Mar 27th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. void fun(int a[], int n) {
  2.     int i, j;
  3.     int temp;
  4.    
  5.     for (i = n - 1; i > 0; i--) {
  6.         for (j = 0; j < i; j++) {
  7.             if (n%2 == 1) {
  8.                 if (a[j] > a[j+1]) {
  9.                     temp = a[j];
  10.                     a[j] = a[j+1];
  11.                     a[j+1] = temp;
  12.                 }
  13.             }
  14.             else if (n%2 == 0) {
  15.                 if (a[j] < a[j+1]) {
  16.                     temp = a[j];
  17.                     a[j] = a[j+1];
  18.                     a[j+1] = temp;
  19.                 }
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement