Skip to content

Commit

Permalink
Merge pull request vishal8113#171 from shrutiujjwal24/master
Browse files Browse the repository at this point in the history
Create primenumber.cpp
  • Loading branch information
vishal8113 authored Oct 31, 2022
2 parents 737ca48 + 4179d1c commit e4886d0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions primenumber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// A school method based C++ program to check if a
// number is prime
#include <bits/stdc++.h>
using namespace std;

bool isPrime(int n)
{
// Corner case
if (n <= 1)
return false;

// Check from 2 to n-1
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;

return true;
}

// Driver Program to test above function
int main()
{
isPrime(11) ? cout << " true\n" : cout << " false\n";
isPrime(15) ? cout << " true\n" : cout << " false\n";
return 0;
}

0 comments on commit e4886d0

Please sign in to comment.