Friday 1 May 2015

C++ Program: Armstrong or Not.

C++ Program: Armstrong or Not.

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
 clrscr();
   int n,m,rem,sum=0;
   cout << "Enter a number to find whether Armstrong or not:";
    cin >> n;
    m = n;
    while(n > 0)
     {
       rem = n%10;
     sum=sum+(rem*rem*rem);
       n=n/10;
      }
  if(m==sum)
    cout << m << " is armstrong";
      else
    cout << m << " is not an armstrong number";
  getch();
}

Output: