Hi, Anybody could you Please tell me How to write the
script for Checking whether given number is Prime Number or
not..Thanks in Advance

Answers were Sorted based on User's Feedback



Hi, Anybody could you Please tell me How to write the script for Checking whether given number is ..

Answer / sumit

//An Extremely Efficient method.
void chkprime(int n)
{
int i=2,j=1;
for(;i<=n/i;j++,i++)
{
if (n%i == 0)
{
break;
}
}

if ( n%i != 0 )
printf("%d is prime. Comparisons: %d\n",n,j);
}

Is This Answer Correct ?    2 Yes 0 No

Hi, Anybody could you Please tell me How to write the script for Checking whether given number is ..

Answer / pankaj jaju

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

Is This Answer Correct ?    0 Yes 0 No

Hi, Anybody could you Please tell me How to write the script for Checking whether given number is ..

Answer / anwar basha

n=cint(inputbox("enter the number"))
if n=0 then
msgbox " invalid no"
end if

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

if falg=1 then
msgbox "not a prime num"
else
msgbox "prime no"
end if

Is This Answer Correct ?    0 Yes 0 No

Hi, Anybody could you Please tell me How to write the script for Checking whether given number is ..

Answer / manu

x=inputbox("enter a number")

prime = TRUE
for i = 0 to x-1
if x mod 2 = 0 then
prime = FALSE
end if
next

if prime then
msgbox "prime number"
else
msgbox "not prime"
end if

Is This Answer Correct ?    0 Yes 2 No

Hi, Anybody could you Please tell me How to write the script for Checking whether given number is ..

Answer / nisar

Dim i,num
num=CInt(InputBox("Enter the numbers to limit the
Prime:"))
i = 3
While i <= num
bIsPrime = True
j = 2
While j <= i\2 And bIsPrime
bIsPrime = i Mod j > 0
j = j + 1
Wend
If bIsPrime Then
Wscript.echo("Found a prime number: " & i)
End If
i = i + 2
Wend

Is This Answer Correct ?    0 Yes 7 No

Hi, Anybody could you Please tell me How to write the script for Checking whether given number is ..

Answer / anant

boolean isPrime(int num){
if(num==0 || num==1){
System.out.println("Number should be greater than 1");
System.Exit(0);
}
if(num%2==0 || num%3==0 || num%5==0 || num%7==0)
System.out.println("Number is not prime");
else
System.out.println("Number is prime");
}

Is This Answer Correct ?    2 Yes 14 No

Post New Answer

More VB Script Interview Questions

Mention how to access array data?

0 Answers  


Which loop is used in case of arrays in the vbscript language?

0 Answers  


Have any one know about Test Complete 6, please let me know. If any one have good material regarding Test Complete 6, Please send to my mail id: cns.praveen@gmail.com

1 Answers  


how to find greatest of n numbers!

3 Answers   Syscon,


How are values assigned to string type and numeric type variables?

0 Answers  






which is the good software training centre in bangalore?

1 Answers  


hai..friends ....what is the difference between function and sub procedure ....here every one know's theoretically here my question is what is the meaning of function can return the value and sub can't return the value...can you give one example with some values for that ....what does it mean ? how function can return the value...sub can not...any one please...........with example

1 Answers   Cap Gemini,


How to identify column in VSFlexgrid? My VSFlexgrid window is identified as 'Active X Control'

0 Answers  


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

0 Answers  


How can the spaces from the string be removed?

0 Answers  


Write a program to display the numbers in the below format using for loops? 1 2 3 4 5 6 7 8 9 10 11 12 and Write a program to display the numbers in the below format using for loops. 1 2 3 4 5 6 7 8 9 10

2 Answers  


If we take 2 strings as “good” and “bad” then what will ‘+’ and ‘&’ operators return?

0 Answers  


Categories