WAP to check whether a given number is Armstrong or not.
This Program in Q-Basic checks whether the number given by the user is Armstrong or not. For this program the number entered should be three digit number.
Number Entered by user is stored in variable N. N is copied to variable T i.e Temp.
While N not equals to 0 each digits of the number is stored to a Variable R i.e
R = N MOD 10.
S whose value was 0 is added with cube of R i.e.
S = S + R ^ 3.
Last digit from the original number is omitted i.e.
N = N \ 10.
Now when programs control comes out of Loop value of S is compared with the Temp value T. If the condition is true it prints “The number is Armstrong.” else prints “The number is not Armstrong.”
CLS INPUT “ENTER A NUMBER”; N T = N WHILE N <> 0 R = N MOD 10 S = S + R ^ 3 N = N \ 10 WEND IF S = T THEN PRINT “The number is Armstrong” ELSE PRINT “The number is not Armstrong” END IF END
For more similar programs Click here