Adsense 728 * 15

Search

Custom Search

Check Armstrong Number using C, C++ Program

Write a C, C++ program to check whether number is Armstrong or not.

Before we start solving this problem let's understand what is Armstrong number.

Armstrong Number

In Armstrong number, the sum of cubes of individual digit is equal to that number itself.

For example - 153 , 371 is an Armstrong number.

153 -  1*1*1 + 5*5*5 + 3*3*3  /* Sum is 153 */

Similarly,

371 - 3*3*3 + 7*7*7 + 1*1*1  /* Sum is 371 */


Take another example let's say 15

15 - 1*1*1 + 5*5*5  /* Sum is 125 */

So 15 is not an Armstrong number.

Program to check whether entered number is Palindrome or not.

C, C++ Program for Practice.


C Program to Check Armstrong Number

#include <stdio.h>

int main(void) {
 
 int num,temp,sum=0,n;
 
 printf("Enter number");
 scanf("%d",&num);
 
 n = num;
 
 while(n>0){
  
  temp = n % 10;
  sum = sum + (temp*temp*temp);
  
  n = n/10;
  
 }
 
 if (num==sum){
  
  printf("\n Enter number is Armstrong number");
  
 } else {
  
  printf ("\n Enter number is not a Armstrong number");
  
 }
 return 0;
}



Output -

Enter number : 153

Enter number is Armstrong number

No comments:

Post a Comment