Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zad1
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- for (int i=0;i<3;i++)
- {
- cout<<rand()% 10 <<endl;
- }
- return 0;
- }
- //zad2
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int a,b;
- a=30;
- b=40;
- srand (time (NULL));
- cout << a+rand()%(b-a+1) << " ";
- cout << a+rand()%(b-a+1) << " ";
- cout << a+rand()%(b-a+1) << " ";
- cout << a+rand()%(b-a+1) << " ";
- cout << a+rand()%(b-a+1) << " ";
- return 0;
- }
- //zad3
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand (time (NULL));
- int s=0;
- for (int i=0;i<100;i++)
- {
- int randInt = rand() % (20-10+1)+10;
- s=s+randInt;
- }
- cout << s << endl;
- return 0;
- }
- //zad4
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int x;
- cout << "Podaj ile razy rzucic moneta: ";
- cin >> x;
- int i=0;
- while(i < x)
- {
- int rzut = rand() %2;
- cout << rzut;
- if(rzut == 0)
- {
- cout << " - orzel" << endl;
- i++;
- }
- else
- {
- cout << " - reszka" << endl;
- i++;
- }
- }
- //albo mamy 0 albo 1, jest to w sumie losowe, a nie zawsze pokazuje sie to samo.
- return 0;
- }
- //zad5
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int x;
- do
- {
- x = -1000+rand()%2001;
- cout<< x <<endl;
- }
- while (x<100 || x>200);
- cout << "Liczba przy ktorej zatrzymal sie program: " << x;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment