C Online Compiler
Example: C Program to Check Armstrong Number using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Check Armstrong Number using Function #include <stdio.h> #include <math.h> // This function will check input number is armstrong or not void CheckArmstrong(int x) { int y, rem, n = 0; float r = 0.0; // y - To store the storage of original input number to check // rem - To store the reminder // r - To store the result variable y = x; // store the number of digits of x in n for (y = x; y != 0; ++n) { y /= 10; } for (y = x; y != 0; y /= 10) { rem = y % 10; // store the sum of the power of individual digits in r r += pow(rem, n); } // if x is equal to r, the number is an Armstrong number if ((int) r == x) { printf("%d is an Armstrong number.\n", x); } else { printf("%d is not an Armstrong number.\n", x); } } // It's the driver function int main() { int x; // To store the input number printf("-----Enter the integer number-----\n"); scanf("%d", &x); CheckArmstrong(x); return 0; }
9474
Output
Clear
ADVERTISEMENTS