C Online Compiler
Example: C Program to Check Armstrong Number without using pow() Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Check Armstrong Number without using pow() Function #include <stdio.h> int main() { int x, y, z, rem = 1, rem2 = 1, n = 0, m = 0; float r = 0.00; // x - To store the input number // y & z - To store the storage of original input number to check // rem & rem2 - To store the reminder values // r - To store the result variable printf("-----Enter the integer number-----\n"); scanf("%d", &x); z = y = x; while (y != 0) { y /= 10; ++n; } m = n; while (z != 0) { rem = z % 10; rem2 = 1; while (n > 0) { rem2 *= rem; --n; } n = m; r += rem2; z /= 10; } // 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); } return 0; }
154
Output
Clear
ADVERTISEMENTS