Write a QBASIC program to accept a multidigit number. Calculate and display the
sum of it’s even digits. (using WHILE -WEND)
Please I need it is urgent
Answers
Answer:
101. WAP to input number and find sum of digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
S = 0
WHILE N < > 0
R = N MOD 10
S = S + R
N = N \ 10
WEND
PRINT "SUM OF DIGITS"; S
END
Answer:
A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number.
For example-
Number= 50113
=> 5+0+1+1+3=10
=> 1+0=1
This is a Magic Number
For example-
Number= 1234
=> 1+2+3+4=10
=> 1+0=1
This is a Magic Number
Examples :
Input : 1234
Output : Magic Number
Input : 12345
Output : Not a magic Number
The approach used brute force. The function keeps adding digits until a single digit sum is reached. To understand how i am calculating the sum upto a single digit view this page- Finding sum of digits of a number until sum becomes single digit