WAP to find whether a 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
USING SUB
DECLARE SUB PERFECT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PERFECT(N)
END
SUB PERFECT(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 SUB
0 Comments