Explore
Placement Prep

Edit

Edit

# Check whether the number is armstrong or not | FACE Prep

Published on 10 Mar 2020

Program to check whether the given number is Armstrong or not is discussed here. A number is an Armstrong number when the sum of nth power of each digit is equal to the number itself. Here n is the number of digits in the given number. For example,

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

## Algorithm

1. Input the number.
2. Initialize sum=0 and temp=number.
3. Find the total number of digits in the number.
4. Repeat until (temp != 0)
5. remainder = temp % 10
6. result = resut + pow(remainder,n)
7. temp = temp/10
8. if (result == number)
9. Display "Armstrong"
10. Else
11. Display "Not Armstrong"

## Program to check whether the number is Armstrong or not

C
C++
Java
Python 3

Output
Input- Enter an integer: 1634 Output- 1634 is an Armstrong number Input- Enter an integer:156 Output- 156 is not an Armstrong number

## Program to check whether the number is Armstrong or not Using Command line

﻿#include<stdio.h>
#include<math.h>
#include int main(int a, char*b[])
{
int n;
n= atoi(b[1]);
int sum=0;
int temp=n;
int cnt=0;
while(n!=0)
{
n=n/10;
cnt++;
}
n=temp;
while(n!=0)
{
int rem=n%10;
sum=sum+pow(rem,cnt);
n=n/10;
}
if(temp==sum)
{
printf(“yes”);
}
else
{
printf(“no”);
}
return 0;
}



Time complexity: O(n)

Recommended Programs