pborawski

tablice / wypisywania / losowanie z funkcji

Jul 15th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. int wylosuj( int start, int stop )
  6. {
  7.         return rand()%( ( stop - start ) + 1 ) + start;
  8. }
  9.  
  10. int main()
  11. {
  12.         srand( time( NULL ) );
  13.         int liczby[ 999 ];
  14.         int licznik = 0, suma = 0;
  15.         do
  16.         {
  17.                 liczby[ licznik ] = wylosuj( 4, 10 );
  18.                 std::cout << "Element o indeksie " << licznik << " : " << liczby[ licznik ] << std::endl;
  19.                 suma += liczby[ licznik ];
  20.                 licznik++;
  21.         } while( licznik <= 999 );
  22.         std::cout << "Suma to: " << suma << std::endl;
  23.         return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment