Tuesday 10 April 2012

Check whether the number is prime or not


n=InputBox("enter the number")
flag=0
For i=2 to (n-1)
If (n mod i)=0 Then
flag=flag+1
Exit for
End If
Next
If flag=1 Then
print " not prime"
else
print "prime"
End If

1 comment:

  1. Dim n
    count=0
    n=inputbox("enter a number")
    For i=2 to n-1
    If n mod i=0 Then
    count=count+1
    End If

    Next
    If (count/2)<> 0 Then
    print "given number is normal number"
    else
    print "given number is prime number"
    End If

    ReplyDelete