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

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();

}

#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**

Categories:
c program

## 2 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

I found an interesting program for Narcissistic Number which is a Super Set of Armstrong Number.

#include

int main()

{

int num1,digit,temp,rem,sum=0;

printf("\n Enter a number:\t");

scanf("%d",&num1);

printf("\n Enter Number of Digits:\t");

scanf("%d",&digit);

temp = num1;

while(temp!=0)

{

rem = temp%10;

sum = sum + power(rem,digit);

temp = temp/10;

}

if(sum == num1)

printf("\n%d is a Narcissistic Number\n",num1);

else

printf("\n%d is not a Narcissistic Number\n",num1);

return 0;

}

int power(int c, int d)

{

int pow = 1;

int count = 1;

while(count<=d)

{

pow = pow*c;

count++;

}

return pow;

}

Source: http://www.codingalpha.com/narcissistic-number-c-program/

## Post a Comment