This a Cpp program to check whether a given number is armstrong or not . Generally a number is said to be an armstrong number if the cubes of the digits is equal to its original number . For Example : 153 is an armstrong number as 1³ + 5³ + 3³ = 153 whereas 234 is not an armstrong number as 2³+ 3³+ 4³ is not equal to 234. |
#include <iostream>
using namespace std;
int main()
{
int n,copy_num,remainder,sum = 0;
cout << "Enter a number : \t" ;
cin >> n;
copy_num = n;
while(n)
{
remainder = n%10;
sum=sum+remainder*remainder*remainder;
n=n/10;
}
if(copy_num == sum)
cout << copy_num << " is an ARMSTRONG number" << endl;
else
cout << copy_num << " is an not an armstrong number" << endl;
return 0;
}OUTPUT : Related Programs :
Armstrong numberin C
Palindrome number in Cpp
Palindrome number in C
Reverse of a number in C
Average of N numbers in Cpp
Average of N numbers in C