Tip
-
Topic
-
Checking Armstrong Number in C
LockedI’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);
}
All Comments
Viewing 2 reply threads