fork(1) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. void wczytywanie( int wczyt[] )
  8. {
  9. cout << "Podaj 3 liczby:" << endl;
  10.  
  11. int i = 0;
  12.  
  13. do
  14. {
  15. cin >> wczyt[ i ];
  16. i++;
  17. } while( i < 3 );
  18.  
  19. }
  20.  
  21. bool sprawdzanie( int wczyt[], int wylos[], int ile, int iLiczba )
  22. {
  23. int i = 0;
  24.  
  25. if( ile <= 0 )
  26. return false;
  27.  
  28. do
  29. {
  30. if( wylos[ i ] == iLiczba )
  31. return true;
  32.  
  33. i++;
  34. } while( i < ile );
  35.  
  36. return false;
  37. }
  38.  
  39. int losowanie()
  40. {
  41. return( rand() % 3 ) + 0;
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. srand(time(NULL));
  48. int wczytane[ 3 ] = {20, 30, 40};
  49. int wylosowane[ 2 ];
  50. int ile = 0;
  51. int i = 0;
  52.  
  53. //wczytywanie( wczytane );
  54.  
  55. do
  56. {
  57. int liczba = losowanie();
  58.  
  59. if( sprawdzanie( wczytane, wylosowane, ile, liczba ) == false )
  60. {
  61.  
  62. cout << wczytane[ liczba ] << ", ";
  63. wylosowane[ i ] = liczba;
  64. ile++;
  65. i++;
  66.  
  67. }
  68.  
  69.  
  70. } while( ile < 2 );
  71.  
  72.  
  73. return 0;
  74.  
  75. }
  76.  
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
40, 20,