Digit fifth powers: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (typo in task description) |
(→{{header|BASIC}}: add QB64) |
||
Line 173: | Line 173: | ||
194979 |
194979 |
||
Total = 443839</pre> |
Total = 443839</pre> |
||
==={{header|QB64}}=== |
|||
<lang qbasic>CONST LIMIT& = 9 ^ 5 * 6 ' we don't need to search higher than this in base 10 |
|||
DIM AS LONG num, sum, digitSum |
|||
DIM digit AS _BYTE |
|||
DIM FifthPowers(9) AS _UNSIGNED INTEGER |
|||
FOR i% = LBOUND(FifthPowers) TO UBOUND(FifthPowers) |
|||
FifthPowers(i%) = i% ^ 5 |
|||
NEXT i% |
|||
FOR i& = 2 TO LIMIT& |
|||
num& = i& |
|||
digitSum& = 0 |
|||
WHILE num& > 0 |
|||
digit%% = num& MOD 10 |
|||
digitSum& = digitSum& + FifthPowers(digit%%) |
|||
num& = INT(num& / 10) |
|||
WEND |
|||
IF digitSum& = i& THEN |
|||
PRINT digitSum& |
|||
sum& = sum& + digitSum& |
|||
END IF |
|||
NEXT i& |
|||
PRINT "The sum is"; sum |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
4150 |
|||
4151 |
|||
54748 |
|||
92727 |
|||
93084 |
|||
194979 |
|||
The sum is 443839 |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |