Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<malloc.h>
  3. #include<stdlib.h>
  4. #include<time.h>
  5.  
  6. int *novo;
  7.  
  8. int fnovo (int *p, int br)
  9. {
  10. int i, m = 0;
  11. novo=NULL;
  12. for (i=0;i<br;i++)
  13. {
  14. if (p[i]%2==0)
  15. {
  16. m++;
  17. novo = ((int*)realloc(novo, m*sizeof(int)));
  18. novo[m - 1]=p[i];
  19. }
  20. }
  21. return m;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. int br, dg, gg, *p, m, i;
  28. printf ("Unesite broj elemenata polja:\n");
  29. scanf ("%d", &br);
  30. printf ("\nUnesite donju i gornju granicu intervala cijelih brojeva:\n");
  31. scanf ("%d %d", &dg, &gg);
  32. p=((int*)malloc(br*sizeof(int)));
  33. srand (time(NULL));
  34. for (i=0; i<br; i++)
  35. p[i]= rand()%(gg-dg+1)+dg;
  36. m = fnovo(&p[0], br);
  37. printf ("staro polje:");
  38. for (i=0; i<br;i++)
  39. printf ("%d ", p[i]);
  40. printf ("\nNovo polje:");
  41. for (i=0; i<m; i++)
  42. printf ("%d ", novo[i]);
  43. printf ("\n");
  44. system("pause");
  45. }
Add Comment
Please, Sign In to add comment