To find the given number is armstrong or not


/* To find the given number is armstrong or not */
# include <stdio.h>
# include <conio.h>
void main()
{
int n, r, s = 0, t ;
clrscr() ;
printf("Enter a number : ") ;
scanf("%d", &n) ;
t = n ;
while(n > 0)
{
r = n % 10 ;
s = s + (r * r * r) ;
n = n / 10 ;
}
if(s == t)
printf("\n%d is an armstrong number", t) ;
else
printf("\n%d is not an armstrong number", t) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter a number : 153
153 is an armstrong number
RUN 2 :
~~~~~~~
Enter a number : 123
123 is not an armstrong number

Comments

Popular posts from this blog

Add Serial no in crystal report without coding

Working with Oracle's BLOB and Microsoft's C#

File operations in C# (.net)