Program to check whether a number is Armstrong or not.

What is armstrong number:-  Click here   


Code:-
#include<stdio.h>
#include<conio.h>
int main()
{
int n,n1,n2,r,s=1,sum=0; //r=reminder
printf(“Enter a number”);
scanf(“%d”,&n);
n1=n;
n2=n;
while(n!=0)
{
r=n%10;
n=n/10;
while(n1!=0)
{
s=s*r;
n1=n1/10;
}
sum=sum+s;
s=1;
n1=n2;
}
if(sum==n2)
printf(“number is Armstrong”);
else
printf(“number is not Armstrong”);
return 0;
}
Output:-
Enter a number
153
number is Armstrong

Recommended Post:

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

Key points:-

 MCQs:-


5 thoughts on “Program to check whether a number is Armstrong or not.

Leave a Reply

Your email address will not be published.