Monday 16 March 2015

Program to generate armstrong numbers Using C

# include <stdio.h>
# include <conio.h>

void main()
{
int i, a, r, s, n ;
clrscr() ;
printf("Enter the limit : ") ;
scanf("%d", &n) ;
printf("\nThe armstrong numbers are :\n\n") ;
for(i = 0 ; i <= n ; i++)
{
a = i ;
s = 0 ;
while(a > 0)
{
r = a % 10 ;
s = s + (r * r * r) ;
a = a / 10 ;
}
if(i == s)
printf("%d\t", i) ;
}
getch() ;
}

RUN 1 :
~~~~~~~
Enter the limit : 1000
The armstrong numbers are :
0 1 153 370 371 407

No comments:

Post a Comment