An official Batch Programming blog! To Solve the daily problems with windows and fixing them with little notepad scripts. Unlock the Hidden Secrets of Windows, Learn to crack Software via CMD & Make your own Programming tools. Understand to Manipulate your PC via CMD.

Print Prime Numbers with Notepad | By Kvc

Print Prime Numbers – Most of us are already familiar with the Prime Numbers, And one of the basic arithmetic we learn in programming is to check these Prime Numbers with LOGIC. While calculating them, I’ve used the unique property of prime numbers that they have only 2 divisors, 1 and the number in question itself.

Print Prime Numbers | By kvc 

HOW TO PRINT PRIME NUMBERS in CMD? | Batch

So, I’ve made two batch files for calculations – but, the algorithm by which they are calculating prime numbers is slightly different. Due to this reason, one is calculating them faster than other.

Two different Algorithms – Same OUTPUT!

Calculate Prime Numbers – Slower Algorithm:

Concept:
This Batch file is simply working blindly on the same fact that a prime number has only two divisors, repeating the second nested FOR LOOP until the number is achieved itself. So, it makes the loop slower as the number (which we have to check is prime or not) gets bigger and bigger. That’s why I called this the slower algorithm.

Check Prime Numbers – Faster Algorithm:

Concept:
This Batch file is based on the fact that if a number is not divisible by any of the basic numbers (i.e. 1 to 13). Then it can be considered as prime numbers.

Because all other numbers can be factorized by these basic numbers, I’m not so sure about the accuracy in all cases of this algorithm (See update at end of page), but it worked fine when tested it 12 to 15 times.

Update: I’ve Again Checked the Faster Algorithm – And, Luckily Found Some Flaws. Using the slower algorithm gives the correct answer with all integers.

Also Read:  Remove Shortcut Virus From Laptop with CMD | Shortcut Virus Remover 2.0

Look at the Difference in the OUTPUT of PRIME NUMBERS UPTO 1000 – with both the Algorithms.

-Kvc

HASH Code - For Verification - (SHA-256)
4e29f7f99b7417e6f9dd4c4d79c94088908cb66f56eb853e027accd9b487ba63

Keep learning, keep sharing….
Be happy, spread happiness…

TheBATeam

Next Post

Previous Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2020 TheBATeam

Our Core Values   /   Terms & Conditions   /   Privacy Policy   /   Why Register?

Theme by Anders Norén