Exercise 9
a) Write a program that displays the sum of the cubes of the digits of any non-negative integer. Two program runs are shown below:
Enter an integer: 145
Sum of digits is 10
Enter an integer: 8888
Sum of the cubes of the digits is 2048
----source file for part A-----
CODE
/* Chapter 4 Exercise 9 by Albert Villaroman 11-20-06 */
#include <iostream.h>
int main() {
long numValue; //user input
cout <<"Enter an integer: ";
cin >>numValue;
long MaxDigits = 100000000;
while (MaxDigits > numValue) { //while loop to get how many digits numValue has
MaxDigits /= 10;
}
long sum = 0; //sum of all digits
while (MaxDigits >=1) {
long digit = numValue / MaxDigits; //get digit
sum += digit*digit*digit;
numValue = numValue % MaxDigits; //enter new value for numValue
MaxDigits /= 10; //ex: 100 => 10
}
int counter = 10;
while (counter < 90000) {
if (sum == numValue) {
cout <<numValue;
}
counter++;
}
cout <<"Sum of the cubes of the digits is " <<sum <<endl;
return(0);
}
#include <iostream.h>
int main() {
long numValue; //user input
cout <<"Enter an integer: ";
cin >>numValue;
long MaxDigits = 100000000;
while (MaxDigits > numValue) { //while loop to get how many digits numValue has
MaxDigits /= 10;
}
long sum = 0; //sum of all digits
while (MaxDigits >=1) {
long digit = numValue / MaxDigits; //get digit
sum += digit*digit*digit;
numValue = numValue % MaxDigits; //enter new value for numValue
MaxDigits /= 10; //ex: 100 => 10
}
int counter = 10;
while (counter < 90000) {
if (sum == numValue) {
cout <<numValue;
}
counter++;
}
cout <<"Sum of the cubes of the digits is " <<sum <<endl;
return(0);
}
What I need help with is part B.
Can someone paraphrase the part B question for me because it just doesn't make sense to me. I'd appreciate a full source file of the second part if you can.
Thank you.


