Friday, November 19, 2010

VBScript Code - Finding whether a number is Prime or not

Write the below code in a notepad and save it as a .vbs file. Either run it from command prompt or run it by double-clicking on it.

VBScript Code - Finding whether a number is Prime or not

sub isprime(a)
flag=1
i=2
While  i < a/2 And flag
 if (a Mod i = 0) then
   flag = 0
 end if
i=i+1
wend

If flag =1 then
  msgbox a & " is  Prime"
else 
  msgbox a & " is NOT Prime"
End if
End sub

isprime(15)