C Program to check Given Number is Armstrong

In this c programming example we will learn

Algorithm

  1. Take an integers from user by printf() function to check which number
  2. Assign this value to other variable check
  3. Take module of this number with 10
  4. Sum these values
  5. divide this value to 10
  6. loop until check value greater than to 0
  7. finally check the sum and given number are equal print given number is Armstrong

 

Simple C example to check given number is Even or Odd

#include <stdio.h>

int main() {
    
   int arms ; 
   
   int check, rem, sum = 0;
   printf("Enter number arms : ");
  
   scanf("%d", &arms); 

   check = arms;

   while(check != 0) {
       
      rem = check % 10;
      
      sum = sum + (rem * rem * rem);
      
      check = check / 10;
   }

   if(sum == arms) 
      printf("%d is an armstrong number.", arms);
   else 
      printf("%d is not an armstrong number.", arms);

   return 0;
}

 

Output

Enter number a : 22                                                                                                           

22 is even    

Enter number a : 27                                                                                                           

27 is odd