Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int *wybierz(int *t1, int n1, int *t2, int n2, int *ilosc);
- int *czytaj1(int *n);
- int main()
- {
- int *t1, *t2, *nowa, n1, n2, ilosc, i;
- printf("podaj1");
- t1=czytaj1(&n1);
- printf("podaj2");
- t1=czytaj1(&n1);
- nowa=wybierz(t1, n1, t2, n2, &ilosc);
- if(ilosc>0){
- printf("W tablicy 1 wystąpiło %d wartosci, ktorych brak w tablicy 2. Oto one: \n", ilosc);
- for(i=0; i<ilosc; i++)
- {
- printf("%d\n", *(nowa+i));
- }
- }
- else printf("W tablicy 1 brak elementow z 2");
- }
- int *wybierz(int *t1, int n1, int *t2, int n2, int *ilosc)
- {
- int *tab_c=NULL, i, k, czy_dodac;
- (*ilosc)=0;
- for(i=0; i<n1; i++)
- {
- czy_dodac=0;
- for(k=0; i<n2; k++)
- {
- if(*(t1+i)!=*(t2+k))czy_dodac=1;
- }
- if(czy_dodac==1){
- (*ilosc)++;
- tab_c=(int*)realloc(tab_c, (*ilosc)*sizeof(int));
- *(tab_c + (*ilosc)-1)=*(t1+i);
- }
- }
- return tab_c;
- }
- int *czytaj1(int *n)
- {
- int *tablica=NULL;
- int liczba;
- while(scanf("%d", &liczba), liczba!=0)
- {
- (*n)++;
- tablica=(int*)realloc(tablica, (*n)*sizeof(int));
- *(tablica+(*n)-1)=liczba;
- }
- return tablica;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement