ARMSTRONG NUMBER
/* Generate all ARMSTRONG number between 1 t0 500 */
An Armstrong number is that whose sum of cube of each digit is equal to the number.
"/" is used instead of "<" and ">".
#include/stdio.h/
#include/conio.h/
main()
{
int i=1,a,b,c;
clrscr();
printf("Armstrong number are\n");
while(i<=500) { a=i%10; /*extract last digit*/ b=i%100; b=(b-a)/10; /*extract second digit*/ c=i/100; /*extract first digit*/ if((a*a*a)+(b*b*b)+(c*c*c)==i) printf("%d",i); i++; } printf("\n\n\nPress any key to exit"); getch(); }
0 comments:
Post a Comment