fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. bool czyBylaWylosowana( int iLiczba, int tab[], int ile )
  6. {
  7. if( ile <= 0 )
  8. return false;
  9.  
  10. int i = 0;
  11. do
  12. {
  13. if( tab[ i ] == iLiczba )
  14. return true;
  15.  
  16. i++;
  17. } while( i < ile );
  18.  
  19. return false;
  20. }
  21.  
  22. int wylosuj()
  23. {
  24. return( rand() % 10 ) + 1;
  25. }
  26.  
  27. int main()
  28. {
  29. srand( time( 0 ) );
  30. int wylosowane[ 5 ];
  31. int wylosowanych = 0;
  32. do
  33. {
  34. int liczba = wylosuj();
  35. if( czyBylaWylosowana( liczba, wylosowane, wylosowanych ) == false )
  36. {
  37. wylosowane[ wylosowanych ] = liczba;
  38. wylosowanych++;
  39. } //if
  40. } while( wylosowanych < 5 );
  41.  
  42. wylosowanych = 0;
  43. do
  44. {
  45. std::cout << wylosowane[ wylosowanych ] << std::endl;
  46. wylosowanych++;
  47. } while( wylosowanych < 5 );
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
4
6
5
2
10