C++ Program to Check given number either Armstrong Number or not.

C++ Program to Check given number either Armstrong Number or not.


#include <iostream.h>
int main()
{
  int origNum, num, rem, sum = 0;
  cout << "Enter a positive  integer: ";
  cin >> origNum;

  num = origNum;

  while(num != 0)
  {
      digit = num % 10;
      sum += digit * digit * digit;
      num /= 10;
  }

  if(sum == origNum)
    cout << origNum << " is an Armstrong number.";
  else
    cout << origNum << " is not an Armstrong number.";

  return 0;
}


Output

Enter a positive integer: 371
371 is an Armstrong number.

Post a Comment

Previous Post Next Post