From e96b4681a9cf6c935c89f53ae8eae84c7eabd36d Mon Sep 17 00:00:00 2001 From: Preetiraj3697 Date: Fri, 14 Apr 2023 15:52:21 +0530 Subject: [PATCH] #10 Create Prime_check.ts in Math function --- maths/prime_check.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 maths/prime_check.ts diff --git a/maths/prime_check.ts b/maths/prime_check.ts new file mode 100644 index 00000000..c158f961 --- /dev/null +++ b/maths/prime_check.ts @@ -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`); +}