Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, a=0;
- int liczba_pierwsza(int n)
- {
- if(n>1)
- {
- for(int i=2; i<=n; i++)
- {
- if(n%i==0)
- {
- a++;
- }
- }
- if(a==1)
- {
- return 1;
- }
- else if(a>1)
- {
- return 0;
- }
- }
- else
- {
- return 0;
- }
- }
- int main()
- {
- cout << "Podaj liczbe naturalna: ";
- cin >> n;
- if(n<0)
- {
- cout<<"To nie jest liczba naturalna";
- return 0;
- }
- if(liczba_pierwsza(n)==1)
- {
- cout<<"Jest to liczba pierwsza";
- }
- else if(liczba_pierwsza(n)==0)
- {
- cout<<"To nie jest to liczba pierwsza";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement