-->

Write a program to accept a number and display whether it is a perfect number or not using QBasic

Write a program to accept a number and display whether it is a perfect number or not. A perfect number is a number whose sum of factors excluding the number is equal to the number itself. For example, 6(1+2+3=6) and 28(1+2+4+7+14-28) are perfect numbers.

QBasic Code: 

Cls

Rem To check whether a number is a perfect number or Not

Input "ENTER THE NUMBER TO CHECK: ", N

SUM = 0

For I = 1 To N / 2

    If N / I = Int(N / I) Then SUM = SUM + I

Next I

If SUM = N Then Print "IT IS A PERFECT NUMBER" Else Print "IT IS NOT A PERFECT NUMBER"

End

Output:
ENTER THE NUMBER TO CHECK: 6
IT IS A PERFECT NUMBER

You May Like Also Also Like This

Post a Comment

0 Comments