#include<stdio.h>
#include<math.h>
#define pow
int main()
{
int num,num1,num2,n,q,sum=0,no_of_digits=0;
printf("enter a number\n");
scanf("%d",&num);
num1=num2=num; //storing the entered number in another variable 'num1'
while (num!=0) //calclating and storing the number of digits in 'digit'
{
num=num/10; //dividing the number by 10. int data type ignores the decimal value, giving an integer
no_of_digits++;
}
while (num1!=0)
{
n=num1%10; //taking one digit at a time in n
q=pow(n,no_of_digits);//each digit^no. of digits
sum=sum+q; // sum of all digit^no. of digits
num1=num1/10;
}
printf("Sum of each digit^no. of digits =%d\n",sum);
if (sum==num2)
printf("%d is an armstrong number\n",num2);
else
printf("%d is NOT an armstrong number\n",num2);
return 0;
}
MY output: Sum of each digit^no. of digits =9 370 is NOT an armstrong number
Also, if i don't add the #define pow line,i get the following error.
/usr/bin/ld: /tmp/ccGBiCYH.o: in function main': 7.c:(.text+0xda): undefined reference to
pow'
collect2: error: ld returned 1 exit status
Please tell me what I'm doing wrong. I checked all the other values (num,num1,....) and they all are right. The 'pow' function doesn't seem to be working correctly.