Odd Number Program In Vbscript

Posted : adminOn 5/28/2018
Odd Number Program In Vbscript

' Performance improvements to generate primes significantly faster than the previous script 'VBScript program to display the prime numbers PrimeNumberLimit = inputbox('Enter the range till (ex: 50):') 'Getting the limit as an input from the user wscript.echo Now() ' echo the start time of the script PrimeNumberList='Prime number list is:' 'Initialising the list of prime numbers PrimeNumberList = '2,3,5' ' Initialise list with numbers we now to be prime but do not want the loop testing. For isPrime=6 to PrimeNumberLimit PrimeFlag=True ' Initialising the Prime Flag variable If Right(isPrime,1) = '1' or Right(isPrime,1) = '3' or Right(isPrime,1) = '7' or Right(isPrime,1) = '9' Then ' We know that prime numbers beyond 5 have a last digit which is either 1, 3, 7, or 9 ' as all numbers greater than 5 whose last digit is 0, 2, 4, 6, 8 are divisible by 2 and all ' numbers greater than 5 whose last digit is 5 is divisible by 5. For primeDivisor=2 to round(sqr(isPrime))+1 ' We don't need to use all the numbers to 1/2 of the number to be tested - we only need ' test to the whole number nearest its square root. Rs232 To Fiber Optic Converter Schematic. Synchro Calculator Updated V1.0. If isPrime mod primeDivisor = 0 Then 'Checking the reminder PrimeFlag=False 'Not a prime number Exit For End If Next Else PrimeFlag=False ' If the number's last digit is 0, 2, 4, 5, 6, or 8 then it is not prime. End If If PrimeFlag=True Then i = i + 1 'wscript.echo isPrime PrimeNumberList=PrimeNumberList & ',' & isPrime 'Collecting the prime numbers if i mod 20 = 0 then wscript.echo PrimeNumberList PrimeNumberList = ' End If ' collect and print the prime numbers in blocks of 20 separated by commas. End If Next if not i mod 20 = 0 then wscript.echo PrimeNumberList ' if the script didn't print out the last group of primes, print it now that the main loop has ended. Autel Ms509 Software Update more.