77 : C Program to find entered number is an armstrong number

Check out the complete list of c-programs : C Program List    





An Armstrong number is that 3 digit number whose sum of the cubes of each digits is equal to the number itself.

Lets see an example :

407 = 4x4x4 + 0x0x0 + 7x7x7 = 407

153 = 1x1x1 + 5x5x5 + 3x3x3 = 153



Logic :
//Armstrong number logic
while(temp_number >=1 ) {
       
      temp_var = temp_number%10; //get unit place digit
      power_of_digit = temp_var*temp_var*temp_var; //find the power
      sum = sum + power_of_digit; //add to sum
      temp_number = temp_number/10; //remove the last digit
       
}










/*
 * 1000+ C programs + tutorials
 *
 * 
 * 77_c_program_to_find_in_entered_number_is_armstrong.c
 *  
 *  
 *
 *  Created on: Oct 25, 2014
 *  Author: Code2care.org
 */

#include 
//#include 

void main() {


int number,temp_number,temp_var,sum,power_of_digit;

//clrscr();

printf("\n Enter a 3 digit number : ");
scanf("%d",&number);

temp_number = number;

while(temp_number >=1 ) {
       
      temp_var = temp_number%10; //get unit place digit
      power_of_digit = temp_var*temp_var*temp_var; //find the power
      sum = sum + power_of_digit; //add to sum
      temp_number = temp_number/10; //remove the last digit
       
   }

     
   if(sum == number) {
       
       printf("\n Entered number %d is a Armstrong Number", number);
   }
   else {
       
        printf("\n Entered number %d is not Armstrong Number", number);
   }
   

 
//getch();  
   
 }










The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.