Home » Blog » Check Number Is Armstrong Or Not

Check Number Is Armstrong Or Not

A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself.

#include <iostream>
using namespace std;

int main()
{
  int origNum, num, rem, sum = 0;
  
  cout << "Enter a positive three digit integer value: ";
  cin >> origNum;
  num = origNum;
  
  while(num != 0)
  {
      rem = num % 10;
      sum += rem * rem * rem;
      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 three digit integer value: 371
371 is an Armstrong number.

 

Leave a Reply

Your email address will not be published.