Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int LICZBA_PIERWSZA(int a)
- {
- if(a<2)
- {
- return 0;
- }
- for(int i=2; i*i<=a; i++)
- {
- if(a%i==0)
- {
- return 0;
- }
- }
- return 1;
- }
- int NASTEPNA_PIERWSZA(int liczba)
- {
- int b;
- liczba=liczba+1;
- while(liczba>0)
- {
- b=liczba;
- if(LICZBA_PIERWSZA(b)==1)
- {
- return liczba;
- }
- else
- {
- liczba++;
- }
- }
- }
- int main()
- {
- int a;
- cout << "Podaj liczbe naturalna: ";
- cin >> a;
- cout << "Po liczbie " << a << " kolejna liczba PIERWSZA jest liczba: ";
- cout << NASTEPNA_PIERWSZA(a)<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement