pc-ip-16.c (788B)
1 /* 2 * Question 16: 3 * Write a C program that includes a user-defined function named isArmstrong with the signature int isArmstrong(int num);. 4 */ 5 6 #include <stdio.h> 7 #include <math.h> 8 9 int isArmstrong(int); 10 11 int main() 12 { 13 int num; 14 printf("Enter the number: "); 15 scanf("%d", &num); 16 if (isArmstrong(num)) 17 { 18 printf("\nInput %d is a Armstrong number.", num); 19 } 20 else 21 { 22 printf("\nInput %d is not a Armstrong number.", num); 23 } 24 return 0; 25 } 26 27 int isArmstrong(int num) 28 { 29 int temp = num; 30 int power = 0; 31 int result = 0; 32 while (temp > 0) 33 { 34 power++; 35 temp /= 10; 36 } 37 temp = num; 38 while (temp > 0) 39 { 40 result += (int)pow((temp % 10), power); 41 temp /= 10; 42 } 43 return result == num; 44 }