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;

}

## Comments

## Leave a comment