Hàm Kiểm Tra Số Nguyên Tố - Gists · GitHub

Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@kayladot7 kayladot7/C++ xây dựng Hàm Created March 25, 2020 16:52 Show Gist options
  • Star (0) You must be signed in to star a gist
  • Fork (0) You must be signed in to fork a gist
  • Embed Select an option
    • Embed Embed this gist in your website.
    • Share Copy sharable link for this gist.
    • Clone via HTTPS Clone using the web URL.

    No results found

    Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/kayladot7/1efa3823871fb4e822ae489fc7f22fc9.js"></script>
  • Save kayladot7/1efa3823871fb4e822ae489fc7f22fc9 to your computer and use it in GitHub Desktop.
Code Revisions 1 Embed Select an option
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/kayladot7/1efa3823871fb4e822ae489fc7f22fc9.js"></script> Save kayladot7/1efa3823871fb4e822ae489fc7f22fc9 to your computer and use it in GitHub Desktop. Download ZIP hàm kiểm tra số nguyên tố Raw C++ xây dựng Hàm This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
#include<iostream>
using namespace std;
// Neu n la so nguyen to thi tra ve True, nguoc lai False
bool Kiem_Tra_So_Nguyen_To(int n)
{
if(n < 2)
{
return false;
}
else
{
if(n == 2)
{
return true;
}
else
{
if(n % 2 == 0)
{
return false;
}
else
{
for(int i = 2; i < n; i++)
{
if(n % i == 0)
{
return false;
}
}
}
}
}
return true;
}
int main()
{
int n;
cout << "\nNhap gia tri n: ";
cin >> n;
// bool kiemtra = Kiem_Tra_So_Nguyen_To(n);
if(Kiem_Tra_So_Nguyen_To(n) == true)
{
cout << n << " la so nguyen to" << endl;
}
else
{
cout << n << " ko la so nguyen to" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Từ khóa » Hàm Kt Số Nguyên Tố