Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 / naga siva sankar

val=Inputbox("enter any number")valprime=0
For i=2 to Int(val/2)
If (val mod i)=0 Then
msgbox "not a prime number"
valprime=1
Exit for
End If
Next
If valprime=0 Then
msgbox "prime number"
End If

Is This Answer Correct ?    37 Yes 15 No

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

Answer / venkat ramana reddy

f=0
msgbox "Enter number"
a=inputbox("enter a no")
For i=1 to a
reminder=a mod i
If reminder=0 Then
f=f+1
End If
Next
If f=2 Then
msgbox "the entered number is prime:"&a
else
msgbox "the entered no.is not prime:"&a
End If

Is This Answer Correct ?    19 Yes 4 No

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

Answer / vinay vuppala

1st method


dim a
dim b
b=1
count=0
a=inputbox("enter a number")
for b=1 to a
if((a mod b)=0) then
count=count+1

end if
next
if count>2 then
msgbox("the number "& a &" is a not prime number")
else
msgbox("the number "& a &" is a prime")
end if

Is This Answer Correct ?    17 Yes 6 No

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

Answer / mudaseer

vnum=inputbox("enter the number")
for i=2 to vnum-1
if(vnum mod i)=0 then
vf="no"
exit for
else vf="yes"
end if
next
if vf="no" then
msgbox "not a prime"
else
msgbox "it is a prime"
end if

Is This Answer Correct ?    9 Yes 1 No

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

Answer / kanikira

a = cint(Inputbox("Enter a number to check whether it is a
prime number or not"))
count = 0
b = 1
Do while b<=a
if a mod b = 0 then
count = count +1
end if
b=b+1
Loop
If count = 2 Then
msgbox "The number "&a& " is a prime number"
Else
msgbox "The number "&a& " is not a prime number"
End if

Is This Answer Correct ?    12 Yes 6 No

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

Answer / ravi salunkhe

val=Inputbox("enter any number")
valprime=0
For i=2 to sqr(val)
If (val mod i)=0 Then
msgbox "not a prime number"
valprime=1
Exit for
End If
Next
If valprime=0 Then
msgbox "prime number"
End If

this will chop off the looping by limiting the loop to the
square root of the number!...\M/...mosh!

Is This Answer Correct ?    4 Yes 0 No

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

Answer / bhanu jay singh

<html>
<head>
<script language="vbscript" for="b1" event="onclick">
a=document.form.t1.value
for c=2 to a-1
if(a mod c)=0 then
x="no"
exit for
else
x="yes"
end if
next
if x="no" then
document.write("not a prime")
else
document.write("prime")
end if
</script>
</head>
<body>
<form name="form">
<input type="text" name="t1">
<input type="button" name="b1" value="find">
</form>
</body>
</html>

Is This Answer Correct ?    4 Yes 1 No

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

Answer / venkat

n=inputbox("enter the number")
count=0
for i= 1 to n
if n mod i=o Then
count=count+1
Endif
Next
if count=2 Then
Msgbox "number is prime"
Else
Msgbox "number is not prime"
Endif

Is This Answer Correct ?    6 Yes 3 No

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

Answer / lak

n=inputbox("Enter a Number to check whether the given
number is prime or not")

flag=1

for i=2 to n-1
if n mod i=0 then
flag=0
end if
next

if flag=1 then
msgbox "Prime"
else
msgbox "not prime"
end if

Is This Answer Correct ?    2 Yes 1 No

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

Answer / pankaja yathindrakumar

' Script to find if the given number is Prime or Not
Function Prime(n)
If n<=1 Then
Exit Function
Else
Flag="Prime"
For i=2 To n-1
If n Mod i=0 Then
Flag ="Not Prime"
End If
Next
End if
Prime=Flag
End Function
Res=Prime(6)
MsgBox Res

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More VB Script Interview Questions

write a vb script to generate fibonnaci numbers

1 Answers  


1)How to test whether items in a weblist are in alphabetical order or not?

1 Answers   TCS,


how many types of recording are there?

1 Answers  


Hi Friends, I am facing some issues with If,else condition,i.e. i am working on some web page for ex:gmail page.now if i want to check if username is incorrect or already exist,i want to display error message in my test report,for this i am using a simple code first,i.e. If Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "Shekhar.g"= true Then Msgbox ("Username Does not Exist!") Else msgbox ("Welcome !") End If But still i am getting a syntax error If Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "shekhar.g"= true Then Msgbox ("Username Does not Exist!") Else msgbox ("Welcome !") End If I don't feel any thing wrong in this syntax but i don't understand why it shows such error,i am confused what went wrong,please help me out & do the favor,thanks a lot....

1 Answers  


Explain about tristate constants?

0 Answers  


if there is any string in a given format like as "company name employeecode date" then we have to fetch employeecode form string for ex-string is "capgemini12345june2013" then we have to fetch 12345 by using vb script so guys how can we do that please reply it.

3 Answers   Cap Gemini,


What is parametrization ?

9 Answers  


How to Import data from a file (file is on the desktop) to the data table

1 Answers   IBM,


Find Out Length of an array without using Ubound?

1 Answers  


What is the difference between Javascript & Vbscript?

2 Answers  


this q asked in applabs, q is: QTP should open google.com page and enter "qtp" in one edit(search) box and click search and should open google.com again and enter "job" in edit(search) box and click on search. I tried this but getting error "Edit(search) box matches more than one object", could anyone this question plz..

1 Answers   AppLabs,


What variable can you use to share info across the whole application for one user?

2 Answers  


Categories