Armstrong number program in c is a program that checks whether the given number is Armstrong number nor not.

What is Armstrong number?
Armstrong of a number is a sum of the Nth power of each digit in number is equal to the number itself. Some Armstrong numbers are 0, 1, 153, 371, etc.

Formula to find Armstrong number
Number = Sum of Nth power of digits in number

Example :
Number = 153
Then sum = 1 ^ 3 + 5 ^ 3 + 3 ^ 3
Sum = 1 + 125 + 27
Sum = 153
So the number is Armstrong number.

Algorithm for Armstrong number program in c

  1. Declare variables. No, temp
  2. Take a number user input. No
  3. Copy number to temp =No
  4. Traverse the number
    i=num%10;
    sum+=i*i*i;
    num=num/10;
    if no == 0
    Break
  5. If sum== temp
    Print number is Armstrong number
    Else
    Print number is not Armstrong number

C program for Armstrong number

#include<stdio.h>
#include<math.h>
void main()
{
int num,i,j,temp,sum=0;;
printf("Enter a number to know whether it is armstrong or not\n");
scanf("%d",&num);
temp=num;
while(num>0)
{
i=num%10;
sum+=i*i*i;
num=num/10;
}
if(sum==temp)
{
printf("Given number %d is an armstrong number\n",temp);
}
else
{
printf("Giveb number %d is not an armstrong number since the sum of cubes of individual digits is %d\n",temp,sum);
}
}

Output :

Armstrong number program in c

Write A Comment