View difference between Paste ID: b3QaBbds and ri5u2XhD
SHOW: | | - or go back to the newest paste.
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;
7+
    
8
    return rand()%( ( stop - start ) + 1 ) + start;
9
}
10
void losujTablice( int t[], int dlugosc, int start, int stop )
11
{
12-
        srand( time( NULL ) );
12+
    srand( time( NULL ) ); 
13-
        int liczby[ 999 ];
13+
    int tmp = 0;
14-
        int licznik = 0, suma = 0;
14+
    do
15-
        do
15+
    {
16-
        {
16+
        t[ tmp ] = wylosuj( start, stop );
17-
                liczby[ licznik ] = wylosuj( 4, 10 );
17+
        tmp++;
18-
                std::cout << "Element o indeksie " << licznik << " : " << liczby[ licznik ] << std::endl;
18+
    } while( tmp <= dlugosc );
19-
                suma += liczby[ licznik ];
19+
20-
                licznik++;
20+
void wypiszTablice( int t[], int dlugosc )
21-
        } while( licznik <= 999 );
21+
22-
        std::cout << "Suma to: " << suma << std::endl;
22+
    int tmp = 0;
23-
        return 0;
23+
    do
24
    {
25
        std::cout << "Liczba z tablicy o indeksie: " << tmp << " to: " << t[ tmp ] << std::endl; 
26
        tmp++;
27
    } while( tmp <= dlugosc );
28
}
29
int obliczSume( int t[], int dlugosc )
30
{
31
    int tmp = 0, suma = 0;
32
    do
33
    {
34
        suma += t[ tmp ];
35
        tmp++;
36
    } while( tmp <= dlugosc );
37
    return suma;
38
}
39
int main()
40
{
41
    int liczby[ 999 ];
42
    losujTablice( liczby, 999, 4, 10 );
43
    wypiszTablice( liczby, 999 );
44
    int iSuma = obliczSume( liczby, 999 );
45
    std::cout << "Suma to: " << iSuma << std::endl;
46
    return 0;
47
}