Armstrong Number
It is a magical number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
153 = (1x1x1)+(5x5x5)+(3x3x3)
where:
(1x1x1)=1
(5x5x5)=125
(3x3x3)=27
So:
1+125+27=153
C Program
//C Program to input a number and
//check whether armstrong number or not
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n, temp=0, r, sum=0;
printf("Enter a number\n");
scanf("%d",&n);
temp=n;
while(n>0)
{
r = n % 10;
sum = sum + (r*r*r);
n = n / 10;
}
if(sum == temp)
printf("%d is an armstrong number",temp);
else
printf("%d is not an armstrong number",temp);
getch();
}
YouTube Video
No comments:
Post a Comment