Armstrong Number

// Armstrong Number.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
# include "iostream"
# include "cmath"
using namespace std;
void main()
{

       int a, b = 0, sum = 0;
       long int n;
       cout << "Enter the NO. : ";
       cin >> n;
       for (; n>0;)
             //counts the digits
       {
             a = n % 10;
             n = n / 10;
             b++;
       }
       for (; n>0;)
       {
             a = n % 10;
             sum = sum + pow(a, b);
             n = n / 10;
       }
       if (sum == n)
       {
             cout << "IT IS AN ARMSTRONG NUMBER...";
       }
       else
       {
             cout << "IT IS NOT AN ARMSTRONG NUMBER...";
       }
       system("pause");
}




Share on Google Plus