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 | By Kvc

Print prime numbers – These are basically very important that they play very important roles in various algorithms and calculations. While calculating them, I’ve used the unique property of prime numbers that they have only 2 divisors, i.e. ‘1’ and the number itself.

Print Prime Numbers | By kvc 


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 others.

Two different Algorithms

Slower Algorithm:

This Batch file is simply working blindly on the same fact that a prime number has only two divisors. And repeating the second nested for a 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 as a slower algorithm.

Faster Algorithm:

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 working of this algorithm, but it worked fine when I tested it 12 to 15 times.

So, I’m almost sure about it. You can match the results with results of a slower algorithm program whose output can be considered as a perfect result.

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

Also Read:  Line Function v.1.0 | By Kvc

Next Post

Previous Post

Leave a Reply

© 2020 TheBATeam

Theme by Anders Norén