CPP Program For Armstrong Number

The sum of the cube of individual digits of a number is equal to the number itself is called Armstrong number.

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int a,n,rev=0,x;

cout << "enter the number" << endl;
cin >>n;

x=n;
while(n>0)
{
a=n%10;
rev=rev+a*a*a;
n=n/10;
}
cout << "cube and sum of the digits=" << rev << endl;

if(rev==x)
{
cout << "Armstrong" << endl;
}
else
{
cout << "Not Armstrong" << endl;
}
getch();
}

Output:
enter the number
371
cube and sum of the digits=371
Armstrong

 

Leave a Reply