Advertisement
MichalWalczak

Zad 21

Mar 30th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. long long int a;
  6.  
  7. long long int LICZBA_PIERWSZA(long long int liczba){
  8.     bool b=true;
  9.     if(liczba==2){
  10.         return 1;
  11.     }
  12.     else{
  13.         for(long long int i=2; i<=sqrt(liczba); i++){
  14.             if(liczba%i==0){
  15.                 b=!b;
  16.                 break;
  17.             }
  18.  
  19.  
  20.     }
  21.          if(b==false){
  22.             return 0;
  23.          }
  24.  
  25.         else{
  26.     return 1;
  27.  }
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     cout << "Podaj liczbe, aby sprawdzic jej pierwszosc" << endl;
  34.     cin>>a;
  35.     if(a<=1){
  36.     cout<<"Liczba ma byc naturalna dodatnia no i rzecz jasna wieksza od 1";
  37.     }
  38.     else if(LICZBA_PIERWSZA(a)==1){
  39.         cout<<"Liczba jest pierwsza";
  40.     }
  41.     else if(LICZBA_PIERWSZA(a)==0){
  42.         cout<<"Liczba jest zlozona";
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement