27 December, 2012

C++ Program To Find & Print An Armstrong Number.

This Post Contains A C++ Program To Find & Print An Armstrong Number With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'While-loop' & 'If...else' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Find & Print An Armstrong Number.

/* Declaration Of Header Files */
# include <iostream.h>
# include <conio.h>

/* Start Of Main Program */
void main()
{
   /* Declaration Of Variables */
   int Num = 0, s, r, t;
   clrscr();

   cout << " Enter Any Number : ";
   cin >> Num;
   t   =   Num;
   s   =   0;
   while ( Num > 0 )
   {
       r = Num % 10;
       s = s + ( r * r * r );
       Num = Num / 10;
   }
   if ( s == t )
   {
      cout << t << " Is An Armstrong Number.";
   }
   else
   {
      cout << t << " Is Not An Armstrong Number.";
   }
   getch();
}
/* End Of Main Program */

Output :

Enter Any Number : 153

153 Is An Armstrong Number.



No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.