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;
}

Axact

Axact

Vestibulum bibendum felis sit amet dolor auctor molestie. In dignissim eget nibh id dapibus. Fusce et suscipit orci. Aliquam sit amet urna lorem. Duis eu imperdiet nunc, non imperdiet libero.

Post A Comment:

0 comments: