# Answer to Question #12994 in C++ for madhurya

Question #12994

program to find the armstrong number between 100 and 999 using c++

Expert's answer

#include <iostream>

using namespace std;

bool

isArmstrongNumber(int number)

{

int sum = 0, temp = number,

remainder;

while(temp != 0)

{

remainder = temp % 10;

sum = sum +

remainder * remainder * remainder;

temp = temp / 10;

}

return (number

== sum);

}

int main()

{

for (int numberToTest = 100;

numberToTest <= 999; numberToTest++)

if

(isArmstrongNumber(numberToTest))

cout << numberToTest << "

";

cout << endl;

return 0;

}

using namespace std;

bool

isArmstrongNumber(int number)

{

int sum = 0, temp = number,

remainder;

while(temp != 0)

{

remainder = temp % 10;

sum = sum +

remainder * remainder * remainder;

temp = temp / 10;

}

return (number

== sum);

}

int main()

{

for (int numberToTest = 100;

numberToTest <= 999; numberToTest++)

if

(isArmstrongNumber(numberToTest))

cout << numberToTest << "

";

cout << endl;

return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment