Question
change the look of my output. ''' #include #include #include using namespace std; int sumDigits(int); int main() { int k2, k3; cout < < List
change the look of my output.
'''
#include
#include
#include
using namespace std;
int sumDigits(int);
int main()
{
int k2, k3;
cout << "List of all positive integers k less than 1000 such that the three "
<< "numbers k, k2, and k3 have digits that add up to the same number: ";
for (int k = 0; k < 1000; k++)
{
k2 = pow(k, 2);
k3 = pow(k, 3);
if (sumDigits(k) == sumDigits(k2) &&
sumDigits(k2) == sumDigits(k3))
cout << k << " ";
}
cout << endl;
return 0;
}
int sumDigits(int Digit)
{
ostringstream ostr;
int num, Sum = 0;
string temp;
ostr << Digit;
string Str = ostr.str();
for (int i = 0; i < Str.length(); i++)
{
temp = Str[i];
istringstream istr(temp);
istr >> num;
Sum += num;
}
return Sum;
}
'''
the following numbers in the output of my program looks like this:
0 1 10 100 468 585
How would I get them to look like this?:
0 1 10 100 468 585
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started