Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- long long int a;
- long long int LICZBA_PIERWSZA(long long int liczba){
- bool b=true;
- if(liczba==2){
- return 1;
- }
- else{
- for(long long int i=2; i<=sqrt(liczba); i++){
- if(liczba%i==0){
- b=!b;
- break;
- }
- }
- if(b==false){
- return 0;
- }
- else{
- return 1;
- }
- }
- }
- int main()
- {
- cout << "Podaj liczbe, aby sprawdzic jej pierwszosc" << endl;
- cin>>a;
- if(a<=1){
- cout<<"Liczba ma byc naturalna dodatnia no i rzecz jasna wieksza od 1";
- }
- else if(LICZBA_PIERWSZA(a)==1){
- cout<<"Liczba jest pierwsza";
- }
- else if(LICZBA_PIERWSZA(a)==0){
- cout<<"Liczba jest zlozona";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement