Could Anybody tell me VBScript for
Check if a given number is Prime number-Don't use any Built-
in Functions Boolean/int is Prime(int number).. Thanks in
advance.

Answers were Sorted based on User's Feedback



Could Anybody tell me VBScript for Check if a given number is Prime number-Don't use any Buil..

Answer / pankaj

Function IsPrime(Num)
Dim varNum, varCtr, varLimit
varLimit = Round(Num/2)

For varCtr = 2 To varLimit
varNum = Num Mod varCtr

If varNum = 0 Then
IsPrime = False
Exit For
End If
Next

If varCtr >= varLimit Then
IsPrime = True
End If
End Function

MsgBox IsPrime(19)

Is This Answer Correct ?    1 Yes 3 No

Could Anybody tell me VBScript for Check if a given number is Prime number-Don't use any Buil..

Answer / sayali

Dim prime, n

prime = TRUE

n=cint(inputbox("Enter a number to find whether it is Prime or Not"))

for i=2 to (n-1)

If n mod i = 0 then
prime = False

Exit for
End if
Next

If prime then
msgbox "Yes! It is a Prime number"
Else
msgbox "No! it is not a prime number"
End if

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More VB Script Interview Questions

wat is com(common object model)object for mozilla firefox??? if any knows the exact answer....plz rply me

2 Answers  


compare the string without using stringcomp function?

1 Answers   CSS Corp,


what types of bugs will we find out in banking projects for automation testing?

0 Answers   Napier Healthcare, TCS,


Explain the functionality of vbscript?

0 Answers  


Explain some uses of vb script?

0 Answers  






how to get date format from system locale..format means neither long nor shor... format from system locale. i need like your date is mm/dd/yyyy formate or mm-dd-yy or with time like that. how to get.

2 Answers  


Like OPTION EXPLICIT statement what are the other statements used in vbscript and their usage. Please post me all the statements please.

0 Answers   Accenture,


which one is more secure vb script or java script ??????? or both are same ??????

3 Answers  


Develop a parameterized action that accomplishes the following a. Launch a browser of users choice ( example : IE, chrome etc) b. Open up a search engine (Google, Bing etc) c. Perform a search d. Click a particular link depending on the user’s choice ( 1st , 2nd or third link)

0 Answers   TCS, Wipro,


What is string concatenation function in VBScript?

2 Answers  


what is extension of the file if its saved from recovery manger to some drive

1 Answers  


What are class events?

0 Answers  


Categories