IP-16.c (1135B)
1 /* Write a C program that includes a user-defined function named isArmstrong with the 2 signature int isArmstrong(int num);. An Armstrong number is a number that is equal to 3 the sum of its own digits each raised to the power of the number of digits. For example, 4 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153 */ 5 6 #include <stdio.h> 7 #include <math.h> 8 9 int isArmstrong(int); 10 int count(int); 11 12 int main() 13 { 14 int n; 15 printf("Enter the number: "); 16 scanf("%d", &n); 17 18 if (isArmstrong(n)) 19 { 20 printf("\nInput %d is a Armstrong Number.", n); 21 } 22 else 23 { 24 printf("\nInput %d is Not a Armstrong Number.", n); 25 } 26 27 return 0; 28 } 29 30 int count(int n) 31 { 32 int count = 0; 33 while (n > 0) 34 { 35 count++; 36 n = n / 10; 37 } 38 return count; 39 } 40 41 int isArmstrong(int n) 42 { 43 if (n < 0) 44 return 0; 45 if (n == 0) 46 return 1; 47 48 int power = count(n); 49 int temp = n; 50 int checker = 0; 51 52 while (temp > 0) 53 { 54 int digit = temp % 10; 55 checker = checker + (int)round(pow(digit, power)); 56 temp = temp / 10; 57 } 58 return n == checker; 59 }