C-programming - Armstrong number in C, C program to find armstrong number

Armstrong number in C

Armstrong numbers are the sum of their own digits to the power of the number of digits. For example consider 153, where 1^3+5^3+3^3= 153.

   int number, sum = 0, temp, remainder;
   printf("Enter a number\n");      
   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.");
      printf("Entered number is not an armstrong number.");         
   return 0;

In this program the number to be checked is got from the user. It is copied to a new variable say temp. Now every digit in the number is raised to a power of number of digits (here it is 3) and summed. If this result is equal to entered number then the number is a armstrong number.


Enter a number
Entered number is not an armstrong number

The topic on C-programming - Armstrong number in C is posted by - Maha

Hope you have enjoyed, C-programming - Armstrong number in CThanks for your time

Tech Bluff