Armstrong number c program
A number is armstrong if
the sum of cubes of individual digits of a number is equal to the number
itself. For example 371 is an armstrong number as 33 + 73
+ 13 = 371. Some other armstrong numbers are: 153, 370,407.
Solve the problem using C programming language.
#include <stdio.h>
#include<conio.h>
void main()
{
int
number, sum =
0, temp, remainder;
clrscr();
printf("Enter an integer\n");
scanf("%d",&number);
temp =
number;
while( temp != 0 )
{
remainder =
temp%10;
sum =
sum + remainder*remainder*remainder;
temp =
temp/10;
}
if ( number == sum
)
printf("%d is
an armstrong number.\n",temp);
else
printf("%d is
not an armstrong number.\n",temp);
}
No comments:
Post a Comment