# C Program to Check if a Given Number is Armstrong Number or Not

Write a Program to check if a given number is an Armstrong number or not

Write the Code in different languages in the comments, we will add this program in the comments section later

### 2 comments on “C Program to Check if a Given Number is Armstrong Number or Not”

• Sushil

#include
int F(int temp,int t)
{
int i,x=1;
for(i=1;i<=t;i++)
{
x=x*temp;
}
return x;
}
int main()
{
int n;
printf("Enter a number :\n");
scanf("%d",&n);
int t=0,sum=0,temp,p=n,q=n;
while(n!=0)
{
t++;
n=n/10;
}
while(p!=0)
{
temp=p%10;
sum=sum+F(temp,t);
p=p/10;
}
if(sum==q)
{
printf("\nArmstrong number.");
}
else
{
printf("\nNot armstrong number.");
}
}

• Anjali

import java.util.*;
import java.io.*;
class arm
{
public static void main(String[] args) {
int sum=0;
Scanner sc=new Scanner(System.in);
String a = sc.next();
char[] ch = a.toCharArray();
for(int i=0;i<ch.length;i++){
sum+=Math.pow(Character.getNumericValue(ch[i]),3);
}

if(sum == Integer.parseInt(a)){
System.out.println("Armstrong Number");
}
else{
System.out.println("Not an Armstrong Number");
}
}
}