Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool LICZBA_PIERWSZA(int l)
- {
- if(l<2)
- {
- return 0;
- }
- else if(l>2&&l%2==0)
- {
- return 0;
- }
- else if(l>3&&l%3==0)
- {
- return 0;
- }
- else if(l>5&&l%5==0)
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- int NASTEPNA_PIERWSZA(int l)
- {
- l++;
- for(int i=1;i<=10;i++&&l++){
- if(l<2||l==1)
- {
- cout<<2;
- return 0;
- }
- else if(l==2)
- {
- cout<<3;
- return 0;
- }
- else if(l>=3&&l<5)
- {
- cout<<5;
- return 0;
- }
- else if(l%2!=0&&l%3!=0&&l%5!=0)
- {
- cout<<l;
- return 0;
- }
- }
- }
- int main()
- {
- int liczba;
- cout << "Podaj liczbe: ";
- cin>>liczba;
- std::cout<<LICZBA_PIERWSZA(liczba)<<endl;
- if(LICZBA_PIERWSZA(liczba)){
- cout<<"Liczba "<<liczba<<" jest liczba pierwsza"<<endl;
- }
- else{
- cout<<"Liczba "<<liczba<<" nie jest pierwsza"<<endl;
- }
- cout<<"Nastepna liczba pierwsza wynosi: ";
- NASTEPNA_PIERWSZA(liczba);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment