Skip to content

Commit

Permalink
TheAlgorithms#10 Create Prime_check.ts in Math function
Browse files Browse the repository at this point in the history
  • Loading branch information
Preetiraj3697 committed Apr 14, 2023
1 parent 3e18b9a commit e96b468
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions maths/prime_check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @function isPrime
* @description program to check if a number is prime or not
* @see [Prime Check](https://www.programiz.com/javascript/examples/prime-number)
* @example Prime Number -> 5,7,11,13,17
* @param {num} number
*/

function isPrime(num: number): boolean {
if (num <= 1) {
return false;
}
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
return false;
}
}
return true;
}


const num: number = 17;
if (isPrime(num)) {
console.log(`${num} is prime`);
} else {
console.log(`${num} is not prime`);
}

0 comments on commit e96b468

Please sign in to comment.