Ask Question
13 September, 01:58

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

+3
Answers (1)
  1. 13 September, 05:46
    0
    Here is code in C++.

    //include header

    #include

    using namespace std;

    / / main function

    int main () {

    / / check for all three digit numbers

    for (int x=100; x<=999; x++) {

    int num = x;

    / / find 1st, 2nd and 3rd digit

    int d1 = x%10;

    int d2 = (x/10) %10;

    int d3 = x/100;

    / / calculate sum of cube of all three digits

    int sum=pow (d1, 3) + pow (d2, 3) + pow (d3,3);

    / / if sum is equal to number then print it

    if (sum = = num) {

    cout<
    }

    }

    return 0;

    }

    Explanation:

    Check all the three digit numbers, if the sum of cubes of digits is equal to the number or not. First extract all three digit and then calculate their cubes. Then sum all those three value And then check if the sum is equal to the number or not. If the sum is equal to number then print the number.

    Output:

    153

    370

    371

    407
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Find all three-digit numbers with non-zero first digit that are equal to the sum of the cubes of their digits. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers