Write VB script to test given number is Prime Number

Answer Posted / rvanamala

'--------- "n" is a given number
n = 101
retval= PrimeNo(n)
If strComp(retVal,"1",1) =0 Then
MsgBox n &" is a Prime Number"
Elseif strComp(retVal,"0",1) =0 Then
MsgBox n &" is not a Prime Number"
Else
MsgBox n &" is -ve Number"
End If

'-------------------
Function PrimeNo(x)
k=0
z=0
If strComp(n,"0",1) = 0 Then
PrimeNo = 0
Exit Function
Elseif n < 0 Then
PrimeNo = -1
Exit Function
End If
For i = 1 to x
IsPrime = 0
If strComp(x,"1",1)= 0 Then
PrimeNo = 0
Exit Function
End If
z = x mod i
If eval("z = 0") and strComp(i,x,1) <>0 and
strComp(i,"1",1) <> 0 Then
PrimeNo = 0
Exit Function
Else
IsPrime= 1
End If

Next

PrimeNo = IsPrime

End Function
'-----------------------------------

Is This Answer Correct ?    0 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Some time when i wanna learn the object i face issue like i am not able learn the object in proper manner... eg:for text bo on web page it should learn as webedit but some times it reads as winobject:internetexpoler-server, because of this i have to uninstall the qtp and re-install it again when i do this it reads the object perfectly.....plz suggest the soln

1397


Thanks....But can u tell me how i use the QTP for GIS with one Example...

1435


how to find that tools work well with your existing system?

1404


How to find the difference between 2 dates in qtp?

586


What does mean by Scope of Automation?n How we defined it?

1579






please any one can explain the keyword driven framework. with gmail example.

1629


write a script to verify the image path(src property) of the images which are in web pages.

1810


There is an built in window application in qtp9.1,i.e.Flight4.0.i want to implement the recovery maneger on it.How can i do this?

1626


Any body have QTP 9.5 licence key. please provide me at madhukar_dec30@yahoo.co.in

1603


Hi. please provide license key for QTP 9.2, I have windows XP on my machine Thanks in Advance, moreshwar

2801


hi frinds i need help .i have 4 + yrs exp in testing and nearly 2 yrs exp in QTP and QC .currently iam working north fast 2 yrs iam looking for job in south is there any openings plz letme know my mail id is pbre1980@gmail.com

1572


hi, FOR 3+ QTP INTERVIEW, FOR EXAMPLE WE PUT ONLINE BANKING SYSTEM PROJECT IN OUR RESUME, IN PROJECT MANAGER ROUND...WHAT R THE MAJOR QUESTIONS ARE ASKED IN P.M? PLS TELL ME ATLEAST 10 QUESTIONS?.....AND IF POSSIBLE POST ANSWERS ALSO....

2440


How can we retrieve the Bug Ids which are open&Reopen in status through QTP scrit?Please find the script which i tried... Dim objBugFactory, objBug Dim BugId Set TDConnection = QCUtil.TDConnection Set objBug = TDConnection.BugFactory If QCUtil.IsConnected then Reporter.ReportEvent 0, "Connected", "Connected to server: " + QCUtil.TDConnection.ServerName + chr (13) +"Project: " + QCUtil.TDConnection.ProjectName + chr (13) + "Domain: " + QCUtil.TDConnection.DomainName Reporter.ReportEvent 0, "Current time on server is","==>" & TDConnection.ServerTime Else Reporter.ReportEvent 1, "Not connected", "Not connected to Quality Center" End If If mybug.Status="Open" Then BugId=mybug.DefectId MsgBox BugId End If 'OR**********************************--------------------- -----********************************** If Bug_Fields("BG_STATUS").Value ="Open" Or "Re Open"Then BugId=Bug_Fields("BG_BUG_ID").Value MsgBox BugId End If

2574


How to find the name of the machine where you are running your automation scripts in qtp?

521


Hi ,Can any one pleas explain how to test splash objects using QTP?

1909