Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define MIN1 -20
- #define MIN2 -19
- #define MAX1 20
- #define MAX2 19
- #define N 3
- #define M 3
- void wypisz(int t_wejscie[], int wymiar);
- void losujParzyste(int t_wejscie[], int wymiar);
- void losujNieparzyste(int t_wejscie[], int wymiar);
- void scalSortuj(int t_wejscieA[], int wymiarA, int t_wejscieB[], int wymiarB, int t_wyjscie[]);
- int main(void)
- {
- int tab1[N];
- int tab2[M];
- int tab3[N+M];
- srand((unsigned)time(NULL));
- losujParzyste(tab1, N);
- wypisz(tab1, N);
- losujNieparzyste(tab2, M);
- wypisz(tab2, M);
- scalSortuj(tab1, N, tab2, M, tab3);
- wypisz(tab3, N+M);
- return 0;
- }
- void wypisz(int t_wejscie[], int wymiar)
- {
- int i;
- for(i=0; i<wymiar; i++)
- {
- printf("%d ", t_wejscie[i]);
- }
- putchar('\n');
- return;
- }
- void losujParzyste(int t_wejscie[], int wymiar)
- {
- int i, p;
- i=0;
- while(i<wymiar)
- {
- p=MIN1+rand()%(MAX1-MIN1+1);
- if(p%2==0)
- {
- t_wejscie[i]=p;
- i++;
- }
- }
- return;
- }
- void losujNieparzyste(int t_wejscie[], int wymiar)
- {
- int i, p;
- i=0;
- while(i<wymiar)
- {
- p=MIN2+rand()%(MAX2-MIN2+1);
- if(p%2==1)
- {
- t_wejscie[i]=p;
- i++;
- }
- }
- return;
- }
- void scalSortuj(int t_wejscieA[], int wymiarA, int t_wejscieB[], int wymiarB, int t_wyjscie[])
- {
- int i, j, k, imin1, min1, imin2, min2, licznik1, licznik2;
- imin1=0;
- imin2=0;
- min1=t_wejscieA[0];
- min2=t_wejscieB[0];
- for(i=1; i<wymiarA; i++)
- {
- if(min1>t_wejscieA[i])
- {
- imin1=i;
- min1=t_wejscieA[i];
- }
- }
- for(j=1; j<wymiarB; j++)
- {
- if(min2>t_wejscieB[j])
- {
- imin2=j;
- min2=t_wejscieB[j];
- }
- }
- for(k=0; k<wymiarA+wymiarB; k++)
- {
- if(min1<min2)
- {
- t_wyjscie[k]=min1;
- t_wejscieA[imin1]=21;
- imin1=0;
- min1=t_wejscieA[0];
- for(i=1; i<wymiarA; i++)
- {
- if(min1>t_wejscieA[i])
- {
- imin1=i;
- min1=t_wejscieA[i];
- }
- }
- continue;
- }
- else
- {
- t_wyjscie[k]=min2;
- t_wejscieB[imin2]=21;
- imin2=0;
- min2=t_wejscieB[0];
- for(j=1; j<wymiarB; j++)
- {
- if(min2>t_wejscieB[j])
- {
- imin2=j;
- min2=t_wejscieB[j];
- }
- }
- continue;
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement