Advertisement
Guest User

Untitled

a guest
May 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. int liczba;
  10. int indeks = 0;
  11. int ilosc = 0;
  12.  
  13. srand(time(NULL));
  14.  
  15. int tablica[50];
  16. for(int i=0;i<50;i++)
  17. {
  18. tablica[i] = (rand()%41)-20;
  19. }
  20.  
  21. cout<<"Podaj liczbe: ";
  22. cin>>liczba;
  23.  
  24. while(indeks < 50)
  25. {
  26. if(tablica[indeks]==liczba)
  27. {
  28. cout<<"Liczba "<<liczba<<" znajduje sie na pozycji: "<<indeks<<endl;
  29. ilosc++;
  30. }
  31. indeks++;
  32. }
  33.  
  34. if(ilosc == 0)
  35. cout<<"Nie znaleziono podanej liczby!"<<endl;
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement