Checking Armstrong Number in C - TechRepublic
Tip
June 13, 2022 at 12:15 PM
Soham1087

Checking Armstrong Number in C

by Soham1087 . Updated 3 years, 2 months ago

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

This discussion is locked

All Comments