# Community

## Tip

• Creator
Topic
• #3977304

### Checking Armstrong Number in C

Locked

by Soham1087 ·

I’m trying to check whether or not the number provided by the user is an Armstrong number in C. Something is wrong though and I can’t figure it out.

Any help is appreciated.

Code attached below.

#include<stdio.h>

int fun(int);

int main()
{
int x,a,b,y=0;

printf(“enter the number you want to identify is aN ARMSTRONG OR NOT:”);
scanf(“%d”,&a);

for(int i=1 ; i<=3 ; i++)
{
b = a % 10;
x = fun(b);
y = x+y;
a = a/10;
}

if(y==a)
printf(“\narmstrong number”);
else
printf(“\nnot an armstrong number”);

return 0;
}

int fun(int x)
{
int a;
a=x*x*x;
return (a);
}

• Author
Replies
• #3977449

### Re: armstrong number

by kees_b ·

In reply to Checking Armstrong Number in C

In such a case you print the intermediate results for x,y, a and b (that are 3 lines, since they are calculated three times) and compare them with your manual calculation for any a that gives the wrong result.

Looks like a homework assignment for a first course in C. Maybe you are a beginning programmer. That’s why I write how to find it yourself.

• #3977605

### Reply To: Checking Armstrong Number in C

by thedomofcode ·

In reply to Checking Armstrong Number in C

First you should read couple of articles on Armstrong Number in C, you will get lot of results on the web which might help you solve the problem, I used to search on the web for my college assignment whenever I get Stuck.

``` #include<stdio.h>```

``` int fun(int); int main() { int x,a,b,y=0; printf("enter the number you want to identify is aN ARMSTRONG OR NOT:"); scanf("%d",&a); for(int i=1 ; i<=3 ; i++) { b = a % 10; x = fun(b); y = x+y; a = a/10; } if(y==a) printf("\narmstrong number"); else printf("\nnot an armstrong number"); return 0; } int fun(int x) { int a; a=x*x*x; return (a); } ```