(Q) Write a QBasic program to enter any number and print if it is a perfect number.
(Hint: A number is said to be perfect if it is equal to the sum of all its factor, e.g., 6 = 1 + 2 +3, hence 6 is a perfect number.)
Answers
Answer:
WAP TO CHECK WHETHER THE INPUT NUMBER IS PERFECT NUMBER OR NOT.
CLS
INPUT "ENTER ANY NUMBER"; N
S = 0
FOR I = 1 TO N - 1
IF N MOD I = 0 THEN S = S + I
NEXT I
IF S = N THEN
PRINT "PERFECT NUMBER"
ELSE
PRINT "NOT PERFECT NUMBER"
END IF
END
Explanation:
The number is not given so we need to Input any number so first step is input N where N is the number
then we need to list the factors of N let's input 28 in N then Factor no. 1 =2 then 14,7,4,1
Then is these factors' sum = N then print perfect or else don't
THE BASIC PROGRAM is here
INPUT N
INPUT "FACTOR 1:"; A
INPUT "FACTOR 2:"; B
INPUT "FACTOR 3:"; C
INPUT "FACTOR 4:"; D
INPUT "FACTOR 5:"; E
IF A+B+C+D+E=N PRINT "PERFECT NUMBER "
IF A+B+C+D+E<> N THEN PRINT "NON PERFECT NUMBER "
OUTPUT
?28
FACTOR 1: 2
FACTOR 2: 14
FACTOR 3: 7
FACTOR 4: 4
FACTOR 5: 1
PERFECT NUMBER