Question

Find all three-digit numbers with non-zero first digit that are equal to the sum of the...

Find all three-digit numbers with non-zero first digit that are equal to the sum of the cubes of their digits.(FORTON)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans: There is only 4 three-digit number that is equal to the sum of the cubes of their digits.

Numbers are:

153, 370, 371, and 407

Procedure:

The three-digit numbers with a non-zero first digit are from 100 to 999.

To find all the three-digit numbers with non-zero first digit that are equal to the sum of the cubes of their digits, we can run a loop from 100 to 999 and check each number whether the number satisfies the property or not.

Here an algorithm to find the numbers:

For example, the code is written in JAVA. (Any language can be used with the same algorithm)

Code:

import java.io.*;
import java.util.*;

public class UniqueNumbers{

   public static void main(String[] args){
      
       for(int i=100;i<=999;i++){               //For loop from 100 to 999

           int number = i;

           int digit1 = i%10;                   //Will give the unit digit of the number
           int digit2 = (i/10)%10;               //Will give the second digit of the number
           int digit3 = i/100;                   //will give the third digit of the number

           //To find the sum of cubes of digit

           int sum = (int)Math.pow(digit1,3) + (int)Math.pow(digit2,3) + (int)Math.pow(digit3,3);

           if(sum == number){

               System.out.println(number+" ");
           }
       }
       System.out.println("");
   }
}

Outputs :

153

370

371

407

Screenshot of full working code along with output:

Add a comment
Know the answer?
Add Answer to:
Find all three-digit numbers with non-zero first digit that are equal to the sum of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT