New User? Please read instructions!

What is Armstrong number?

Sum of a number's digits raised to the power total number of digits is armstrong number.

Armstrong numbers example: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634 etc

Explanation:

3 = 3^1 = 3

153 = 1^3 + 5^3 + 3^3 = 153

Non-Armstrong numbers:

156 = 1^3 + 5^3 + 6^3 . This value is equal to 342. So, 156 is not an armstrong number

**To find whether a number is Armstrong number or not, please use below C program.**

#include <stdio.h>

int main()

{

int n, sum = 0, t, remainder;

printf("\nPlease enter a number to find whether it is an armstrong or not");

scanf("%d",&n);

t = n;

while( t != 0 )

{

remainder = t%10;

sum = sum + remainder*remainder*remainder;

t = t/10;

}

if ( n == sum )

printf("\nThe number %d is an armstrong number", n);

else

printf("\nThe number %d is not an armstrong number", n);

return 0;

}

Hi Prakash,

In the while loop, I see that we have remainder brought to the third power. However, from the definition of what an armstrong number is that you listed, it looks like for a number with 1 digit, it will be raised to the 1 power, a power with 2 digits, each digits will be raised to the 2 power and then we find the sum of that. Hence, remainder will not always be raised to the third power but rather to the number of digits the number has. For a more explicit example, 1634 is an armstrong number because it has 4 digits and 1634 = 1^4 + 6^4 + 3^4 + 4^4.

#include<stdio.h>

#include<math.h>

void main()

{

int number, a, b, c, sum=0, count=0;

printf("\n Enter the number");

scanf("%d",&number);

a=number;

b=a;

while(a>0)

{

count++;

a=a/10;

}

while(b>0)

{

c=b%10;

sum=sum+pow(c,count);

b=b/10;

}

printf("\n sum=%d",sum);

if(sum==number)

printf("\n The number is Armstrong");

else

printf("\n The number is not Armstrong");

getch();

}

**OTHER C PROGRAMS:**

- C program for prime number
- C program for factorial
- C program for fibonacci series
- C program for palindrome
- C program for swapping 2 numbers with and without temp variables
- C program to find leap year
- C program to find armstrong number
- C program to find simple and compound interest
- C program to find largest of given 3 numbers
- C program to find smallest of given 3 numbers
- C program to convert lower case into upper case and vice versa
- C program to find sum and average of given 3 numbers
- C program to sum up all individual digits
- C program to reverse given number
- C program to reverse given string
- C program to find strong number
- C program to find square and cube of given number
- C program to print hello world without using semi colon
- C program to sort given names in alphabetical order
- C program to copy content of one file to another
- C program to sort given numbers in ascending order
- C program to sort given numbers in descending order
- C program to search given number in an array
- C program for recursive function
- C program for calculator application
- C program for bank application
- C program to check given number is perfect number or not
- C program to find array size
- C program to find whether given character vowel or not
- C program to check whether given number is positive or negative
- C program to find sum of n numbers
- C program to compare 2 numbers without if statement
- C program to generate random numbers
- C program to compare 2 arrays whether they are equal or not
- C program to print number from 1 to 500 without using any loop conditions
- C program to insert an element into an array
- C program to delete an element from an array
- C program to find hcf (gcd) and lcm
- C program to print diamond pattern
- C program to print pascal triangle
- C program to add two complex numbers
- C program for binary search
- C program for linear search
- C program for matrix addition
- C program for matrix multiplication
- C program for bubble sort
- C program for insertion sort
- C program for selection sort