Ask Question

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

+4
Answers (1)
  1. 29 April, 05:58
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers