Advertisement
ahmad_zizo

Algo1

Mar 31st, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int arr[]={-5,4,0,22,-3,0,5,7,-4,-8};
  7.     int i=0,j=0,t,n=10;
  8.  
  9.     while(arr[i]<0)
  10.         i++;
  11.     j=i;
  12.     i++;
  13.     for(;i<n;i++){
  14.         if(arr[i] < 0){
  15.             t = arr[i];
  16.             arr[i] = arr[j];
  17.             arr[j] = t;
  18.             j++;
  19.         }
  20.     }
  21.     i=j;
  22.     while(arr[i]==0)
  23.         i++;
  24.     j=i;
  25.     i++;
  26.     for(;i<n;i++){
  27.         if(arr[i] == 0){
  28.             t = arr[i];
  29.             arr[i] = arr[j];
  30.             arr[j] = t;
  31.             j++;
  32.         }
  33.     }
  34.     for(i=0;i<n;i++)
  35.         printf("%d\t",arr[i]);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement