Ask Question
29 June, 03:22

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

+1
Answers (1)
  1. 29 June, 05:20
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers