Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int *wybierz(int *t1, int n1, int *t2, int n2, int *ilosc);
  5. int *czytaj1(int *n);
  6. int main()
  7. {
  8.     int *t1, *t2, *nowa, n1, n2, ilosc, i;
  9.     printf("podaj1");
  10.  
  11.     t1=czytaj1(&n1);
  12.     printf("podaj2");
  13.     t1=czytaj1(&n1);
  14.     nowa=wybierz(t1, n1, t2, n2, &ilosc);
  15.     if(ilosc>0){
  16.         printf("W tablicy 1 wystąpiło %d wartosci, ktorych brak w tablicy 2. Oto one: \n", ilosc);
  17.         for(i=0; i<ilosc; i++)
  18.         {
  19.             printf("%d\n", *(nowa+i));
  20.         }
  21.     }
  22.     else printf("W tablicy 1 brak elementow z 2");
  23. }
  24.  
  25. int *wybierz(int *t1, int n1, int *t2, int n2, int *ilosc)
  26. {
  27.     int *tab_c=NULL, i, k, czy_dodac;
  28.     (*ilosc)=0;
  29.     for(i=0; i<n1; i++)
  30.     {
  31.         czy_dodac=0;
  32.         for(k=0; i<n2; k++)
  33.         {
  34.             if(*(t1+i)!=*(t2+k))czy_dodac=1;
  35.         }
  36.         if(czy_dodac==1){
  37.              (*ilosc)++;
  38.              tab_c=(int*)realloc(tab_c, (*ilosc)*sizeof(int));
  39.              *(tab_c + (*ilosc)-1)=*(t1+i);
  40.         }
  41.     }
  42.     return tab_c;
  43. }
  44. int *czytaj1(int *n)
  45. {
  46.     int *tablica=NULL;
  47.     int liczba;
  48.     while(scanf("%d", &liczba), liczba!=0)
  49.     {
  50.         (*n)++;
  51.         tablica=(int*)realloc(tablica, (*n)*sizeof(int));
  52.         *(tablica+(*n)-1)=liczba;
  53.     }
  54.     return tablica;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement