Question: Description Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: 1634 = 14 + 64
Description Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: 1634 = 14 + 64 + 34 + 44 8208 = 84 + 24 + 04 + 84 9474 = 94 + 44 + 74 + 44 Find all of the 5 digit numbers that can be written as the sum of fifth powers of their digits. You may declare any variables of any type (although you may not use char or string types), you may create any custom functions, please provide necessary comments to your code.
#include
int main () {
int sum, rep; int counter = 10000; int num[4];
while (counter < 100000) { rep = counter; for(int i = 0; i < 5; i++) { num[i] = rep % 10; rep = rep/10; sum = sum + pow(num[i], 5); } if (sum == counter) { cout << counter << endl; }
rep = 0; sum = 0; counter++; } return 0; }
not sure why my code keeps giving an infinite loop of nothing
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
