Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- void pierwszoscDoskonaloscNieparzystosc(int a,bool *czyp,bool *czyd,bool *czypier)
- {
- *czypier=true;
- int sumaDz=0;
- if(a%2!=0) *czyp=true;
- else *czyp=false;
- for(int i=1;i<a;i++)
- {
- if(a%i==0)
- {
- sumaDz=sumaDz+i;
- }
- }
- if(sumaDz==a) *czyd=true;
- else *czyd=false;
- for(int j=2; j*j<=a; j++)
- {
- if(a%j==0)
- {
- *czypier=false;
- break;
- }
- }
- if(a<=1) *czypier=false;
- }
- int main()
- {
- int liczba,sumaDz;
- bool czyp,czyd,czypier;
- cout<<"Podaj liczbe: ";
- cin>>liczba;
- pierwszoscDoskonaloscNieparzystosc(liczba,&czyp,&czyd,&czypier);
- if(czyp==true) cout<<"Liczba jest nieparzysta";
- else cout<<"Liczba jest parzysta";
- cout<<endl;
- if(czyd==true) cout<<"Liczba "<<liczba<<" jest doskonala";
- else cout<<"Liczba "<<liczba<<" nie jest doskonala";
- cout<<endl;
- if(czypier==true) cout<<"Liczba "<<liczba<<" jest pierwsza";
- else cout<<"Liczba "<<liczba<<" nie jest pierwsza";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement