Program to Check Armstrong Number.

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

153 = 1 * 1 * 1 + 5 * 5 * 5 + 3 * 3 * 3  // 153 is an Armstrong number.
12 is not equal to 1 * 1 * 1 + 2 * 2 * 2  // 12 is not an Armstrong number.

Program:-

#include <iostream.h>
#include<conio.h>
void main()
{
  int origNum, num, rem, sum = 0,digit;
  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.";

getch();
}

Output:-
Output of the Program to Check Armstrong Number.
output!!!

Post a Comment

0 Comments