Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include using namespace std;

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Know how to approach on-the-job training

Answered: 1 week ago