78 : C Program to print armstrong numbers between 1 to 999

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





We have seen in the previous program what an armstrong number is, now lets print all armstrong numbers between 1 to 999.








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

#include 
//#include 

void main() {


int number,temp_number,temp_var,sum,power_of_digit,i;

//clrscr();

printf("\n Armstrong number between 1 to 999");




for(i = 0 ; i <=1000;i++)
{

    temp_number = i;      
    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 == i) {
       
       printf("\n Entered number %d is a Armstrong Number", i);
        }
  
      sum = 0;
       
   }
 

 
//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.