Post Page Advertisement [Top]

C-Programming

Write a program in c to check given number is armstrong or not using function??

Home /c-programming//write a program in c to check given number is armstrong or not using function??
Write a program in c to check given number is Armstrong or not using function??
  

/*illustrate code*/ 
#include<stdio.h>
#include<conio.h>
int arm(int,int);
void main()
{int n,sum=0,temp,remainder,digits=0;
printf("\n input an integer");
scanf("%d",&n);
temp=n;
while(temp!=0)
{digits++;
temp=temp/10;
}
temp=n;
while(temp!=0)
{remainder=temp%10;
sum=sum+arm(remainder,digits);
temp=temp/10;}
if(n==sum)
printf("%d is an armstrong number:",n);
else
printf("%d is not armstrong number:",n);
getch();
}
int arm(int n,int r)
{int c,p=1;
for(c=1;c<=r;c++)
p=p*n;
return p;

}

No comments:

Post a Comment

Bottom Ad [Post Page]