Advertisement
MeehoweCK

Untitled

Mar 26th, 2024
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. bool czyPierwsza(unsigned int liczba) {
  4.     if (liczba < 2) {
  5.         return false;
  6.     }
  7.     for (auto i{ 2 }; i * i <= liczba; ++i) {
  8.         if (liczba % i == 0) {
  9.             return false;
  10.         }
  11.     }
  12.     return true;
  13. }
  14.  
  15. int main() {
  16.     unsigned int liczba;
  17.     std::cout << "Podaj liczbe naturalna: ";
  18.     std::cin >> liczba;
  19.     if (czyPierwsza(liczba)) {
  20.         std::cout << liczba << " jest liczba pierwsza.\n";
  21.     }
  22.     else {
  23.         std::cout << liczba << " nie jest liczba pierwsza.\n";
  24.     }
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement