Advertisement
Guest User

4B

a guest
Mar 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. void generuj (int n, int tab[]);
  8. void wypisz (int n, int tab[]);
  9. void przepisz (int n, const int tab1[], int tab2[]);
  10. int
  11. main ()
  12. {
  13.  
  14. int tabA[10], tabB[10];
  15. int n;
  16. printf ("ile n ");
  17. scanf ("%d", &n);
  18.  
  19.  
  20. generuj (n, tabA);
  21. printf ("tabA: \n");
  22. wypisz (n, tabA);
  23. przepisz (n, tabA, tabB);
  24. printf ("\n tabB: \n");
  25. wypisz (n, tabB);
  26. return 0;
  27. }
  28.  
  29. void
  30. generuj (int n, int tab1[])
  31. { /*funkcja GENERUJ */
  32. int i;
  33. srand ((unsigned) time (NULL));
  34. for (i = 0; i < n; i++)
  35. {
  36. tab1[i] = rand () % 10 - 5;
  37. }
  38. }
  39.  
  40. void
  41. wypisz (int n, int tab1[])
  42. { /*funkcja WYPISZ */
  43. int i;
  44. for (i = 0; i < n; i++)
  45. {
  46. printf ("%4d", tab1[i]);
  47. }
  48. }
  49.  
  50. void
  51. przepisz (int n, const int tab1[], int tab2[])
  52. { /*funkcja PRZEPISZ */
  53. int i;
  54. for (i = 0; i < n; i++)
  55. {
  56. if (tab1[i] >= 0)
  57. {
  58. tab2[i] = tab1[i];
  59. }
  60. else
  61. {
  62. tab2[i] = 0;
  63. }
  64.  
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement