Friday, March 16, 2012

ArmStrong Number

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.


Write a program to find all Armstrong number in the range of 0 and 999.





#include<stdio.h>
#include<conio.h>
 
main()
{
   int number, sum = 0, temp, remainder;
 
   printf("Enter a number\n");      
   scanf("%d",&number);
 
   temp = number;
 
   while( temp != 0 )
   {
      remainder = temp%10;
      sum = sum + remainder*remainder*remainder;
      temp = temp/10; 
   }
 
   if ( number == sum )
      printf("Entered number is an armstrong number.");
   else
      printf("Entered number is not an armstrong number.");         
 
   getch();
   return 0;
}

Output:





 Further Reading....
http://www.programmingsimplified.com/c-program-find-armstrong-number

No comments:

Post a Comment