Q97 Write a C Program to find an Armstrong number.

Before writing a program we should know what is Armstrong number.

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

# include < stdio.h >
# include < conio.h >

int main()
{

int num = 0, s, r, t;
clrscr();

printf ( ” \n Enter any number : ” );
scanf ( ” %d “, &num );
t   =   num;
s   =   0;
while ( num > 0 )
{
r = num % 10;
s = s + ( r * r * r );
num = num / 10;
}
if ( s == t )
{
printf ( ” \n %d Is an Armstrong number.”, t );
}
else
{
printf ( ” \n %d Is not an Armstrong number.”, t );
}
return 0;

}

Output :

Enter any number : 153

153 Is an Armstrong number.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.