Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. #define MAX_ARRAY_SIZE 100
  6.  
  7. int CheckOddOrEven(int type, int x[], int y[], int z[]); // 1 - ODD, 2 - EVEN
  8.  
  9. void main()
  10. {
  11.     int BigOne[MAX_ARRAY_SIZE],
  12.         Even[MAX_ARRAY_SIZE],
  13.         Odd[MAX_ARRAY_SIZE];
  14.  
  15.     for(int i = 0; i < MAX_ARRAY_SIZE; i++)
  16.     {
  17.         BigOne[i] = rand() % 10;
  18.     }
  19.  
  20.     PrintInConsole(BigOne, Even, Odd);
  21. }
  22.  
  23. int CheckOddOrEven(int type, int x[], int y[], int z[]) // 1 - ODD, 2 - EVEN
  24. {
  25.     int even = 0, odd = 0;
  26.  
  27.     for(int i = 0; i < MAX_ARRAY_SIZE; i++)
  28.     {
  29.         if(x[i] % 2 == 0)
  30.         {
  31.             y[even] = x[i];
  32.             even++;
  33.         }
  34.         else
  35.         {
  36.             z[odd] = x[i];
  37.             odd++;
  38.         }
  39.     }
  40.  
  41.     if(type == 1) return odd;
  42.     else if(type == 2) return even;
  43. }
  44.  
  45. void PrintInConsole(int x[], int y[], int z[])
  46. {
  47.     printf("Lyginiai skaiciai: \n");
  48.     for(int i = 0; i < CheckOddOrEven(2, x, y, z); i++)
  49.         printf("%d ", y[i]);
  50.  
  51.     printf("\n");
  52.  
  53.     printf("Nelyginiai skaiciai: \n");
  54.     for(int i = 0; i < CheckOddOrEven(1, x, y, z); i++)
  55.         printf("%d ", z[i]);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement