C Online Compiler
Example: Armstrong Number Checker in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Armstrong Number Checker #include <stdio.h> int main() { int num, originalNum, remainder, sum = 0; // Step 1: Prompt user for input and read the number printf("Enter a three-digit integer: "); scanf("%d", &num); originalNum = num; // Store the original number for comparison later // Step 2: Loop to extract digits and calculate the sum of cubes while (originalNum != 0) { remainder = originalNum % 10; // Get the last digit sum += remainder * remainder * remainder; // Add cube of the digit to sum originalNum /= 10; // Remove the last digit } // Step 3: Compare the sum with the original number using if-else if (sum == num) { printf("%d is an Armstrong number.\n", num); } else { printf("%d is not an Armstrong number.\n", num); } return 0; }
Output
Clear
ADVERTISEMENTS