Interview Questions   Tutorials   Discussions   Programs   Videos   

QTP - Write VB script to test given number is Prime Number?




974
views
asked marvit October 10, 2014 10:07 AM  

Write VB script to test given number is Prime Number?


           

2 Answers



 
answered By Hitesh-1047   0  

'VBScript program to display the prime numbers PrimeNumberLimit = inputbox("Enter the range till (ex: 50):") 'Getting the limit as an input from the user

PrimeNumberList="Prime number list is:" 'Initialising the list of prime numbers

For Ctr1=1 to PrimeNumberLimit

PrimeFlag=True ' Initialising a Flag variable

If Ctr1>=4 Then

  For Ctr2=2 to Ctr1/2

     If Ctr1 mod Ctr2 = 0 Then 'Checking the reminder

        PrimeFlag=False
        'Not a prime number

     End If

  Next

End If

If PrimeFlag=True Then

  PrimeNumberList=PrimeNumberList&" "&Ctr1
  'Collecting the prime numbers

End If

Next

Msgbox PrimeNumberList 'Displaying the result

flag   
   add comment

 
answered By Hitesh-1047   0  

'VBScript program to display the prime numbers PrimeNumberLimit = inputbox("Enter the range till (ex: 50):") 'Getting the limit as an input from the user

PrimeNumberList="Prime number list is:" 'Initialising the list of prime numbers

For Ctr1=1 to PrimeNumberLimit

PrimeFlag=True ' Initialising a Flag variable

If Ctr1>=4 Then

  For Ctr2=2 to Ctr1/2

     If Ctr1 mod Ctr2 = 0 Then 'Checking the reminder

        PrimeFlag=False
        'Not a prime number

     End If

  Next

End If

If PrimeFlag=True Then

  PrimeNumberList=PrimeNumberList&" "&Ctr1
  'Collecting the prime numbers

End If

Next

Msgbox PrimeNumberList 'Displaying the result

flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert