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

Armstrong number in C

#include
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.


#include<conio.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;
}


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.

output

Enter a number
123
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