Wednesday, July 20, 2011

Program to check armstrong no. of any digit {Version 2}

/*Serial No.70     [swami43.cpp]*/ 

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long int i,num,m,sum,dig,p=0,n,x,z;
clrscr();
sum=0;
printf("Enter the number=");
scanf("%ld",&n);
num=n;
z=n;
for(i=1;i<=10;i++)
{
x=z/10;
z=x;
p=p+1;
if(z==0)
break;
}
for(i=1;i<=p;i++)
{dig=n%10;
n=n/10;
sum=pow(dig,p)+sum;
 }
if(num==sum)
printf("\nArmstrong no.");
else
printf("\n Not Armstrong no.");
getch();
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...