C Program to Check a given Number is Armstrong or Not.
In this example, we will check a number entered by the user whether it is an Armstrong number or not. To solve this program we should have a proper concept on Armstrong number, while loop and if-else statement.
What is an Armstrong Numer?
An Armstrong number is a positive number that is equal to the sum of the power of the digits.
For Example: Let's take 153: 13 + 53 + 33
= 1 + 125+ 27
= 153
which means 153 is an Armstrong number.
PROGRAM
#include<stdio.h>
#include<conio.h>
int main()
{
int num,a,r,sum=0;
printf("\n Enter the Number : ");
scanf("%d",&num);
a=num;
while(a>0)
{
r=a%10;
sum=sum+r*r*r;
a=a/10;
}
if(num==sum)
{
printf("\n%d is an Armstrong Number.",num);
}
else
{
printf("\n%d is Not an Armstrong Number.",num);
}
return 0;
}
OUTPUT
NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section. Let's Learn together.
MOTTO:
You Learn, I Learn together We Learn.
Comments
Post a Comment
Please do not spam any link