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?

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

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

### Join with account you already have

Preview

Online-Classroom Classes
www.writeabc.com

1 person following this question

1 person following this tag

Question tags

qtp × 1

Asked 3 years and 5 months ago ago
Number of Views -974
Number of Answers -2
Last updated
3 years and 2 months ago ago

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!