Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- int wylosuj( int start, int stop )
- {
- return rand()%( ( stop - start ) + 1 ) + start;
- }
- void losujTablice( int t[], int dlugosc, int start, int stop )
- {
- srand( time( NULL ) );
- int tmp = 0;
- do
- {
- t[ tmp ] = wylosuj( start, stop );
- tmp++;
- } while( tmp <= dlugosc );
- }
- void wypiszTablice( int t[], int dlugosc )
- {
- int tmp = 0;
- do
- {
- std::cout << "Liczba z tablicy o indeksie: " << tmp << " to: " << t[ tmp ] << std::endl;
- tmp++;
- } while( tmp <= dlugosc );
- }
- int obliczSume( int t[], int dlugosc )
- {
- int tmp = 0, suma = 0;
- do
- {
- suma += t[ tmp ];
- tmp++;
- } while( tmp <= dlugosc );
- return suma;
- }
- int main()
- {
- int liczby[ 999 ];
- losujTablice( liczby, 999, 4, 10 );
- wypiszTablice( liczby, 999 );
- int iSuma = obliczSume( liczby, 999 );
- std::cout << "Suma to: " << iSuma << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment