Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>//poniewa¿ "sqrt"
- using namespace std;
- int a,b;
- int liczba_pierwsza(int a)
- { int b=2;
- int c=1;
- a=sqrt(pow(a,2));//math.h
- while (b<a)
- {
- if(a%b==0)
- {c=0;}
- b++;
- }
- return c;}
- int nastepna_pierwsza(int a)
- {
- a=sqrt(pow(a,2))+1;
- int b=2;
- while (b<a)
- {
- if(a%b==0)
- {a++;}
- b++;
- }
- return a;
- }
- int main()
- {
- cout<<"Podaj liczbe naturalna"<<endl;
- cin >> a;
- if(liczba_pierwsza(a)==1)
- {cout << "Podana liczba jest pierwsza";}
- else
- {cout << "podana liczba nie jest pierwsza "<<endl;}
- cout<<"następna liczba pierwsza po "<<endl;
- cout<<a<<" to "<<nastepna_pierwsza(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement