//An armstrong number is an number in which the sum of cubes of the digits of the number equals the number.
For eg: 153 = 1(1's cube) + 125(5's cube) + 27(3's cube)
#include<stdio.h>
#include<conio.h>
void armstrong(); //Function declaration
void main()
{
int num, a;
printf("\nEnter an integer number: ");
scanf("%d", &num);
armstrong(num); //Function call
getch();
}
void armstrong(int p)
{
int t, cube, scube=0, d;
t=p;
while(p>0)
{
d=p%10; //Separating digit's
cube=d*d*d; //Cube of separated digit
scube=scube+cube; //Adding cube to sum of cube(scube)
p=p/10;
}
if(scube==t)
printf("\nGiven number is armstrong\n");
else
printf("\nGiven number is not armstrong\n");
return;
}
SAMPLE OUTPUT:
No comments:
Post a Comment