Input a number and determin that is an Armstrong number or not. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ).
N.B. [ Armstrong Numbers : - 1, 153, 370, 371, 407. ]
#include <stdio.h>
#include <conio.h>
void main ( )
{
int no, no1, md, s = 0;
clrscr ( );
printf ("\n\t Enter a number.........:"); scanf ("%d",&no);
no1 = no;
while ( no > 0 )
{
md = no % 10;
no = no /10;
s = s + ( md * md * md );
}
if ( no1 == s )
printf ("\n\t Number = %d is an Armstrong number", no1);
else
printf ("\n\t Number = %d is not an Armstrong number", no1);
getch ( );
}
No comments:
Post a Comment