Armstrong number or not

Write a program to find number is Armstrong or not.

In this program we will find the number is Armstrong  or not where the number should be entered by the user. Basically the sum of cube of its digits is equal to the number itself is called  Armstrong number.

Ex:- Enter any number 153. 

 1**3 + 5**3 + 3**3 = 153

Number is Armstrong 

Armstrong number or not in C programming(1)

Working:-

Step 1.Initialize variables num,n,n1,c=0,mul=1,sum=0,r,f,i .

Step 2.Input any number by user so read num variable.

Step 3.set n=num and n1=num for duplicate.

Step 4.We use while loop with condition(n!=0).

Step 5.Than check last digit of a number with condition is  reminder(r)=number(n)%10.

Step 6.Than increment of other variable for next step (c++).

Step 7.Than find length of number with condition is  number(n)=number(n)/10.

Step 8.repeat steps 4 to 6 until number (n)!=0.

Step 9.Again we use while loop with condition (num!=0) for check

Step 10.the number is Armstrong or not.

Step 11.Again check last digit for duplicity of number with condition is reminder(r1)=number(num)%10.

Step 12.Than we use for loop statement with condition is (i=1;i<=c).

Step 13.Use this code mul=mul*r1, sum=sum+mul, num=num/10;

Step 14.For find number is armstrong.

Step 15.The check if (n1==sum) display number is armstrong

Step 16.Either false display number is not armstrong

Step 17.stop

C program:-

#include<stdio.h>
int main()
{
int num ,n,n1,c=0,mul=1,sum=0,r,f,i;
printf("enter any num: \n");
scanf("%d",&num);
n=num;
n1=num;
while(n!=0)
{
r=n%10;
c++;
n=n/10;
}
while (num!=0)
{
f=num%10;
mul=1;
for(i=1;i<=c;i++)
{
mul=mul*f;
}

sum=sum+mul;
num=num/10;
}
if(n1==sum)
printf("Armstrong Number");
else
printf("Not an Armstrong Number");
return 0;
}

Output:-

enter any num: 1634

Armstrong Number.


enter any num: 135

Not an Armstrong Number.

Please Login/Signup to comment