# 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
# 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
No comments:
Post a Comment