ziobrowskyy

Untitled

Nov 24th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <time.h>
  3.  
  4. #define size 10
  5.  
  6.  
  7. getRandInt(int min, int max) {
  8. return rand() % (max - min + 1) + min;
  9. }
  10.  
  11. void main() {
  12.  
  13. srand(time(0));
  14.  
  15. int tab[size] = {0};
  16. int min = 0, max = 10;
  17. for(int i = 0; i < size; i++) {
  18. tab[i] = getRandInt(min, max);
  19. printf("%d\n", tab[i]);
  20. }
  21.  
  22. printf("Podaj szukana wartosc z zakresu %d do %d\n", min, max);
  23. int x;
  24. scanf("%d", &x);
  25.  
  26. int inde x = -1;
  27.  
  28. for(int i = 0; i < size; i++) {
  29. if(tab[i] == x) {
  30. index = i;
  31. break;
  32. }
  33. }
  34.  
  35. if(index == -1) {
  36. printf("Nie znaleziono tej liczby w tablicy");
  37. } else {
  38. printf("Liczba znajduje sie na pozycji %d w tablicy", index);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment