QBasic Program to check whether the two entered numbers are amicable or not.
DECLARE SUB amc(a,b)
CLS
INPUT "enter any two numbers"; a, b
CALL amc(a, b)
END
SUB amc (a, b)
FOR i = 1 TO a - 1
IF a MOD i = 0 THEN s = s + i
NEXT i
FOR j = 1 TO b - 1
IF b MOD j = 0 THEN t = t + j
NEXT j
IF a = t AND b = s THEN
PRINT "amicable numbers"
ELSE
PRINT " not amicable numbers"
END IF
END SUB
Amicable Number Examples: 220, 284
Algorithm :
1. First ask the user to enter both numbers.
2. Find the sum of all divisors for both numbers.
3. Finally check if the sum of the divisors of one number is equal to the other number or not.
4. If yes, it is a Amicable number and otherwise not.
2. Find the sum of all divisors for both numbers.
3. Finally check if the sum of the divisors of one number is equal to the other number or not.
4. If yes, it is a Amicable number and otherwise not.
No comments:
Post a Comment