C Program to Check Armstrong Number

Overview
In numerical number theory, the Armstrong number definition is the number in any given number base, which forms the total of the same number when each of its digits is raised to the power of the number of digits in the number.
Prerequisites
Check Armstrong Number of three digits
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Algorithm (for a 3-digit Number)
Step 1: Start.
Step 2: Read an integer input number.
Step 3: Initialize the variables current_digit, sum = 0, and num = number.
Step 4: Repeat Steps 5 to 7 until num > 0.
Step 5: current_digit = (num % 10).
Step 6: sum = sum + (current_digit * current_digit * current_digit).
Step 7: num = num / 10.
Step 8: Check if sum == number. If true, print "It is an Armstrong Number." Otherwise, print "It is not an Armstrong Number."
Step 9: END
Program for Three-Digit Armstrong Number in C
Here's a C program to check whether a given three-digit number is an Armstrong number:
Output:
Check Armstrong Number of N digits
Turn Learning into Career Growth
Algorithm (for N-digit Number)
Step 1: Start.
Step 2: Read an integer input number.
Step 3: Initialize the variables current_digit, sum = 0, digits = 0, and num = number.
Step 4: Calculate the number of digits in the input integer number and store it in the variable number_of_digits.
Step 5: Repeat Steps 5 to 7 until num > 0.
Step 6: current_digit = (num % 10).
Step 7: sum = sum + pow(current_digit, number_of_digits).
Step 8: num = num / 10.
Step 9: Check if sum == number. If true, print "It is an Armstrong Number." Otherwise, print "It is not an Armstrong Number."
Step 10: END
Program for N-Digit Armstrong Number in C
Here's a generalized C program to check whether a given N-digit number is an Armstrong number:
Output:
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Armstrong Number Using Functions
Refactoring code to use functions can enhance its modularity, readability, and reusability. In this section, we'll demonstrate how to check for an Armstrong number using functions in C.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Functions in Use
1. Function to Calculate Number of Digits:
- Purpose: Calculates the number of digits in the given number.
- Input: Integer (number).
- Output: Integer (number of digits).
2. Function to Check Armstrong Number:
- Purpose: Checks if a number is an Armstrong number.
- Input: Integer (number).
- Output: Integer (1 if Armstrong, 0 otherwise).
Main Program
- The main program takes an integer input.
- Calls the isArmstrong function to check if the number is an Armstrong number.
- Displays the result based on the output from the isArmstrong function.
Conclusion
- We have discussed what Armstrong numbers are, and then we have seen a C program to check for a three-digit number, whether it is Armstrong or not.
- We have learned about a more generalized version of it for N-digit numbers.