September 5, 2011

C Program to Find whether Number is a Armstrong Number or Not

C Program to Find whether Number is a Armstrong Number or Not
Also known as narcissistic numbers, Armstrong numbers are the sum of their own digits to the power of the number of digits. As that is a slightly brief wording, let me give an example:
153 = 1³ + 5³ + 3³


Each digit is raised to the power three because 153 has three digits. They are totalled and we get the original number again! Notice that Armstrong numbers are base dependent, but we'll mainly be dealing with base 10 examples
Sample Output:


Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,b,c,d;
clrscr();
printf("Enter The Value");
scanf("%d",&n);
a=n%10;
b=n%100;
b=(b-a)/10;
c=n/100;


if(n==(a*a*a)+(b*b*b)+(c*c*c))
printf("It's An Armstrong No.");


else
printf("It's Not An Armstrong No.");
getch();
}

Comment bello for your Query and Feedback

Related Posts :



Categories:

1 comments:

No, its not the correct answer! for 3 digit number only you checking, while if 4 digit number means? example 1634 is an armstong number 1pow4+6pow4+3pow4+4pow4=1634

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails