ziobrowskyy

szukanie w tablicy / c

Nov 24th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 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.     for(int i = 0; i < size; i++) {
  26.         if(tab[i] == x) {
  27.             printf("Podana wartosc znajduje sie na pozycji %d", i);
  28.             break;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment