Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <iostream>
- using namespace std;
- bool czy_pierwsza(int N)
- {
- if(N<2){
- return false; //gdy liczba jest mniejsza ni¿ 2 to nie jest pierwsz¹, zwracamy false i wychodzimy
- }
- for(int i=2;i<N;i++) {
- if(N%i==0) {
- return false; //gdy znajdziemy dzielnik, to dana liczba nie jest pierwsza, zwracamy false i wychodzimy z funkcji
- }
- }
- return true;
- }
- int main()
- {
- int N;
- cout << "ile liczb pierwszych ci podac:" ;
- cin >> N ;
- int i=0;
- int x=2;
- while(i<N){
- if (czy_pierwsza(x)==true){
- cout << x << " ";
- i++;
- }
- x++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement