Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include "stdio.h"
  3. #include "math.h"
  4. #include "stdlib.h"
  5. #include "time.h"
  6.  
  7. int main()
  8. {
  9. int liczba[6];
  10. int losowa[6];
  11. int wystepowanie[6];
  12. int min = 1;
  13. int max = 49;
  14. int L = max - min + 1;
  15. srand(time(NULL));
  16. printf("Podaj 6 liczb od 1 do 49\n");
  17. for (int i = 0; i <= 5; i++)
  18. {
  19. wystepowanie[i] = 0;
  20. }
  21. //WPROWADZAM LICZBY
  22. for (int i = 0; i <= 5; i++)
  23. {
  24. scanf("%d", &liczba[i]);
  25. }
  26. //GENERUJE LICZBY LOSOWE
  27. for (int i = 0; i <= 5; i++)
  28. {
  29. losowa[i] = rand() % L + min;
  30. }
  31. //SPRAWDZAM CZY WPROWADZONE LICZBY SĄ Z ZADANEGO PRZEDZIAŁU
  32. for (int i = 0; i <= 5; i++)
  33. {
  34. if (liczba[i] < 1 || liczba[i] > 49)
  35. {
  36. printf("Ktoras z zadanych liczb nie spelnia wymagan przedzialu");
  37. system("pause");
  38. }
  39. }
  40.  
  41. for (int i = 0; i <= 5; i++)
  42. {
  43. for (int n = 0; n <= 5; n++)
  44. {
  45. if (liczba[i] == losowa[n])
  46. {
  47. wystepowanie[i]++;
  48. }
  49. }
  50. }
  51.  
  52. printf("Liczby losowe w tym losowaniu to: ");
  53. for (int i = 0; i <= 5; i++)
  54. {
  55. printf("%d ", losowa[i]);
  56. }
  57. printf("\nLiczba %d powtarzala sie %d razy", liczba[1], wystepowanie[1]);
  58. system("pause");
  59. }
  60.  
  61. /*int main()
  62. {
  63. int min = 1;
  64. int max = 49;
  65. int L = max - min + 1;
  66. int losowa[6];
  67. srand(time(NULL));
  68. for (int i = 0; i <= 5; i++)
  69. {
  70. losowa[i] = rand() % L + min;
  71. }
  72. for (int i = 0; i <= 5; i++)
  73. {
  74. printf("%d\n", losowa[1]);
  75. }
  76. system("pause");
  77. }
  78. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement