Note: Armstrong numbers are those numbers if we take cube of their digits individually and add them then it will equal to the number.
e.g: 153
1^3 + 5^3 + 3^3 = 153
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int remainder, temp, sum=0, num, i;
cout << "Enter a number: ";
cin >> i;
num = temp = i;
while(temp != 0)
{
remainder = temp%10;
sum = sum + remainder*remainder*remainder;
temp = temp/10;
}
if(num == sum)
cout << "Number is Armstrong." <<endl;
else
cout << "Number is not Armstrong." <<endl;
getch();
}
Write a program to find given given number is armstrong or not?
Tuesday, 1 July 2014
Labels:
C++,
C++ Language,
Loops (For While Do-While)