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

write a program to display the system specifications of client system with the help of vbScript.

0 Answers  


write a program to display configuration of a local system with the help of vb script.

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  


Explain the string concatenation function in vbscript?

0 Answers  


How to pass the parameter from one function to another function in VB Scripting?

1 Answers   Fastenal,






. Program for sorting of numbers in vb script?

2 Answers   Talent Sprint,


Explain different types of segment?

0 Answers  


I have an excel sheet with multiple ID's in a column. Now i need fetch those ID's in an application and check whether if it already exist in the DB. If not then i have to go with the process of inserting them in the DB. If it exists then i need to skip that ID and move to the next ID and check the same and proceed. How can i do that with for loop and if condition?

0 Answers  


HOw we can apply web service checkpoint in QTP 9.5? I tried it out with net connection also. But not getting success.

0 Answers  


HI how can handle dynamic image through vb script example we have to create email id fill the edit box(these latters change wrong password) i am wating your answer

1 Answers  


what is descriptive programming in QTP and what is environment variable in QTP? where we store and what is its use?

4 Answers   Perot Systems,


How can you destroy an object in vbscript?

0 Answers  


Categories