Advertisement
Guest User

Exercicio 2

a guest
Oct 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int* uniao(int *x1, int *x2, int n1, int n2, int *qtd)
  5. {
  6. int tam=(n1+n2);
  7. int i=0, j=0;
  8.  
  9. qtd=(int*)malloc(tam*sizeof(int));
  10.  
  11. for(i=0; i<n1; i++)
  12. {
  13. *(qtd+i)=*(x1+i);
  14. }
  15. for(i=n1; i<tam; i++,j++)
  16. {
  17. *(qtd+i)=*(x2+j);
  18.  
  19.  
  20. }
  21.  
  22. return(qtd);
  23.  
  24.  
  25. }
  26.  
  27. int main()
  28. {
  29. int x1[]={1,3,5,6,7}, x2[]={1,3,4,6,8}, n1=5, n2=5, *x3=0, *qtd=0;
  30. int i;
  31.  
  32. x3=uniao(x1,x2,n1,n2,&qtd);
  33.  
  34. for(i=0; i<10; i++)
  35. {
  36. printf("%d\t", *(x3+i));
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement