Advertisement
Guest User

Labki1

a guest
Dec 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define MIN1 -20
  5. #define MIN2 -19
  6. #define MAX1 20
  7. #define MAX2 19
  8. #define N 3
  9. #define M 3
  10. void wypisz(int t_wejscie[], int wymiar);
  11. void losujParzyste(int t_wejscie[], int wymiar);
  12. void losujNieparzyste(int t_wejscie[], int wymiar);
  13. void scalSortuj(int t_wejscieA[], int wymiarA, int t_wejscieB[], int wymiarB, int t_wyjscie[]);
  14.  
  15. int main(void)
  16. {
  17.     int tab1[N];
  18.     int tab2[M];
  19.     int tab3[N+M];
  20.     srand((unsigned)time(NULL));
  21.     losujParzyste(tab1, N);
  22.     wypisz(tab1, N);
  23.     losujNieparzyste(tab2, M);
  24.     wypisz(tab2, M);
  25.     scalSortuj(tab1, N, tab2, M, tab3);
  26.     wypisz(tab3, N+M);
  27.     return 0;
  28. }
  29.  
  30. void wypisz(int t_wejscie[], int wymiar)
  31. {
  32.     int i;
  33.     for(i=0; i<wymiar; i++)
  34.     {
  35.         printf("%d ", t_wejscie[i]);
  36.     }
  37.     putchar('\n');
  38.     return;
  39. }
  40.  
  41. void losujParzyste(int t_wejscie[], int wymiar)
  42. {
  43.     int i, p;
  44.     i=0;
  45.     while(i<wymiar)
  46.     {
  47.         p=MIN1+rand()%(MAX1-MIN1+1);
  48.         if(p%2==0)
  49.         {
  50.             t_wejscie[i]=p;
  51.             i++;
  52.         }
  53.     }
  54.     return;
  55. }
  56.  
  57. void losujNieparzyste(int t_wejscie[], int wymiar)
  58. {
  59.     int i, p;
  60.     i=0;
  61.     while(i<wymiar)
  62.     {
  63.         p=MIN2+rand()%(MAX2-MIN2+1);
  64.         if(p%2==1)
  65.         {
  66.             t_wejscie[i]=p;
  67.             i++;
  68.         }
  69.     }
  70.     return;
  71. }
  72.  
  73. void scalSortuj(int t_wejscieA[], int wymiarA, int t_wejscieB[], int wymiarB, int t_wyjscie[])
  74. {
  75.     int i, j, k, imin1, min1, imin2, min2, licznik1, licznik2;
  76.     imin1=0;
  77.     imin2=0;
  78.     min1=t_wejscieA[0];
  79.     min2=t_wejscieB[0];
  80.     for(i=1; i<wymiarA; i++)
  81.     {
  82.         if(min1>t_wejscieA[i])
  83.         {
  84.             imin1=i;
  85.             min1=t_wejscieA[i];
  86.         }
  87.     }
  88.     for(j=1; j<wymiarB; j++)
  89.     {
  90.         if(min2>t_wejscieB[j])
  91.         {
  92.             imin2=j;
  93.             min2=t_wejscieB[j];
  94.         }
  95.     }
  96.     for(k=0; k<wymiarA+wymiarB; k++)
  97.     {
  98.         if(min1<min2)
  99.         {
  100.             t_wyjscie[k]=min1;
  101.             t_wejscieA[imin1]=21;
  102.             imin1=0;
  103.             min1=t_wejscieA[0];
  104.             for(i=1; i<wymiarA; i++)
  105.             {
  106.                 if(min1>t_wejscieA[i])
  107.                 {
  108.                     imin1=i;
  109.                     min1=t_wejscieA[i];
  110.                 }
  111.             }
  112.             continue;
  113.         }
  114.         else
  115.         {
  116.             t_wyjscie[k]=min2;
  117.             t_wejscieB[imin2]=21;
  118.             imin2=0;
  119.             min2=t_wejscieB[0];
  120.             for(j=1; j<wymiarB; j++)
  121.             {
  122.                 if(min2>t_wejscieB[j])
  123.                 {
  124.                     imin2=j;
  125.                     min2=t_wejscieB[j];
  126.                 }
  127.             }
  128.             continue;
  129.         }
  130.     }
  131.     return;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement