Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zadanie 1
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int i;
- srand(time(NULL));
- for (i = 0; i < 3; i++)
- {
- cout << rand() % (9 + 1) << endl;
- }
- }
- // Zadanie 2
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int i;
- int a = 30;
- int b = 40;
- srand(time(NULL));
- for (i = 0; i < 5; i++)
- {
- cout << a + rand() % (b - a + 1) << " ";
- }
- }
- // Zadanie 3
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int i;
- int a = 10;
- int b = 20;
- int suma = 0;
- int x;
- srand(time(NULL));
- for (i = 0; i < 100; i++)
- {
- x = a + rand() % (b - a + 1);
- suma = suma + x;
- }
- cout << suma << endl;
- }
- // Zadanie 4
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int i;
- int x;
- srand(time(NULL));
- x = rand() % (1 + 1);
- if (x == 0)
- {
- cout << "Orzel" << endl;
- }
- else
- cout << "Reszka" << endl;
- /* Wyniki są losowe */
- }
- // Zadanie 5
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int i;
- int x;
- int a=-1000;
- int b=1000;
- srand(time(NULL));
- do
- {
- x = a + rand() % (b - a + 1);
- cout << x << endl;
- } while (x <=100 || x >= 200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement