Program to check a number for being Armstrong number
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int number = 0, temp_number = 0, remainder = 0,
number_cube = 0;
cout
<< "\n\n ______ Program to check a number for being
Armstrong ______";
cout
<< "\n\n\n Enter the Number ->
";
cin
>> number;
number_cube
= 0;
temp_number
= number;
while(temp_number != 0)
{
remainder
= temp_number % 10;
temp_number
= temp_number / 10;
number_cube
= number_cube + remainder * remainder * remainder;
}
cout
<< "\n\n\t\t";
if (number_cube == number)
{
cout
<< number << " is an Armstrong
number";
}
else
{
cout
<< number << " is not an Armstrong
number";
}
getch();
return 0;
}
A number is an Armstrong number if the sum of the cube of its digits is equal to the original number.
No comments:
Post a Comment