0% found this document useful (0 votes)
362 views

VB Script PRime No

The document contains 6 responses providing VBScript code to check if a given number is prime without using built-in functions. The responses implement different approaches like checking for divisibility from 2 to the square root of the number, counting the number of factors, and using a flag variable.

Uploaded by

_d0wn
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
362 views

VB Script PRime No

The document contains 6 responses providing VBScript code to check if a given number is prime without using built-in functions. The responses implement different approaches like checking for divisibility from 2 to the square root of the number, counting the number of factors, and using a flag variable.

Uploaded by

_d0wn
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Re: 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. Answer #1

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 ?

13 Yes

2 No

0 Naga Siva Sankar Re: 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. Answer #2

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 ?

4 Yes

3 No

0 Kanikira

Re: 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. Answer #3

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 ?

6 Yes

2 No

0 Venkat Ramana Reddy Re: 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. Answer #4

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 end if


Is This Answer Correct ?

prime")

5 Yes

1 No

0 Vinay Vuppala Re: 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. Answer #5

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 ?

1 Yes 0 No 0 Ravi Salunkhe Re: 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. Answer #6

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

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 Read more: http://wiki.answers.com/Q/How_can_find_prime_number_by_using_if_in_vbscript#ixzz1XHeP B9Fe

Option Explicit Dim i,j,var,Flag,n var="" n=cint(InputBox("Enter nth Number to check Prime Numbers"))

i=3 While i <= n Flag = True j=2 While j <= i\2 And Flag Flag = i Mod j > 0 j=j+1 Wend If Flag Then var = var&" "&i End If i=i+2 Wend MsgBox("Prime numbers within n numbers "&n&"= : 1" & var) Read more: http://wiki.answers.com/Q/How_do_you_write_a_vbscript_code_for_displaying_the_prime_nu mbers_between_1_and_100#ixzz1XHemZ5zv

flag=1 primeNo=inputbox("Enter a number") For i=2 to primeNo flag=1 For j=2 to i/2 If i mod j=0 Then flag=0 End If Next

If flag=1 Then msgbox i End If Next

You might also like