Articles by "Beginner"
Showing posts with label Beginner. Show all posts
no image
A page about Blogging Tricks and Computer, Android, Hacking, and Windows Tricks.

C Program to test whether the given number is an Armstrong Number.




Armstrong Number:

A number is Armstrong if the sum of cubes of individual digits of a number is equal to the number itself.  

for example :

370 = 3^3 + 7^3 + 0^3

371 = 3^3 + 7^3 + 1^3

407 = 4^3 + 0^3 + 7^3

#include
 
int main()
{
   int number, sum = 0, temp, remainder;
 
   printf("Enter an integer\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.\n");
   else
      printf("Entered number is not an armstrong number.\n");
 
   return 0;
}