Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application that finds all 4 digit numbers (those would be the numbers

ID: 3547806 • Letter: C

Question

Create an application that finds all 4 digit numbers (those would be the numbers in the range 1000-9999) whose value is equal to the sum of each digit raised to the fourth power.

For example, if 1^4 + 2^4 + 3^4 + 4^4 = 1234, then your program would print 1234 as one of the solutions that meets the criteria.


I am completely lost and I'm not sure where to start. This program needs to be written in C. If you are able to help me out, please write a simplified code with some comments to explain. I'm still in the beginning stages of programming and I'm trying to learn this quickly.

Explanation / Answer

#include <stdio.h>

int power(int a)

{

return a*a*a*a;

}

int main(void) {

int i,a,b,sum;

for(i=1000;i<=9999;i++)

{

sum=0;

a = i;

while(a!=0)

{

b = a%10;

sum+=power(b);

a=a/10;

}

if(sum==i)

printf("%d ",i);

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote