SHARE
TWEET

Untitled

a guest May 24th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include <time.h>
  5.  
  6. #define n 20
  7.  
  8. void fnOdd(int mas[], int size)
  9. {
  10.     int tmp, i = 0, k = size - 1;
  11.    
  12.     while (i < k)
  13.     {
  14.         if (mas[k] % 2 == 0 && mas[i] % 2 != 0)
  15.         {
  16.             tmp = mas[k];
  17.             mas[k] = mas[i];
  18.             mas[i] = tmp;
  19.             ++i;
  20.             --k;
  21.         }
  22.         if (mas[i] % 2 == 0) ++i;
  23.         if (mas[k] % 2 != 0) --k;
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.     srand(time(0));
  30.  
  31.     int mas[n];
  32.  
  33.  
  34.     for (int i = 0; i < n; i++)
  35.     {
  36.         mas[i] = rand() % 100;
  37.     }
  38.  
  39.  
  40.     for (int i = 0; i < n; i++)
  41.     {
  42.         printf("%d  ", mas[i]);
  43.     }
  44.     printf("\n\n");
  45.  
  46.     fnOdd(mas, n);
  47.  
  48.  
  49.     for (int i = 0; i < n; i++)
  50.     {
  51.         printf("%d  ", mas[i]);
  52.     }
  53.     printf("\n");
  54.     getchar(); getchar();
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top