-->

Write a program to accept a number and display whether the number is a prime number or not using QBasic

Write a program to accept a number and display whether the number is a prime number or not. A prime number has no factors excluding 1 and the number itself. 

Cls

Rem To check whether a number is a prime number or not

Input "ENTER THE NUMBER TO CHECK: ", N

NUMOFFACTORS = 0

For I = 2 To N / 2

    If N / I = Int(N / I) Then NUMOFFACTORS = NUMOFFACTORS + 1

Next I

If NUMOFFACTORS = 0 Then Print "IT IS A PRIME NUMBER" Else Print "IT IS NOT A PRIME NUMBER"

End

Output: 

ENTER THE NUMBER TO CHECK:7

IT IS A PRIME NUMBER

You May Like Also Also Like This

Post a Comment

0 Comments