
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program for Armstrong Numbers
We are given a task where we have to check a number n entered by the user, whether it’s Armstrong or not.
An Armstrong number is when the sum of all the digits power by the number of digits or we can say order of digits n, is same as the digit.
So below is a simple representation how to find the Armstrong number −
Formula −
wxyz…. = pow(w, n) +pow(x, n) + pow(y, n) + pow(z, n) + …..
Algorithm
START Step 1-> Declare a function to find the value after power operation on the number int power(int a, int b) Loop while b>0 Assign power =power * a Decrement b by 1 End loop Return power End Step 2-> Declare a function to count the order of a number int count(int n) Declare and set i as 0 Loop while n!=0 Increment i by 1 Divide n/10 and store back in n End loop Return i End Step 3-> Declare a function to check number is prime or not int armstrong(int n) Declare x and call function count(n) and assign the result to x Declare rem = 0 and m=0 set with zero Loop While n Set rem = n %10 Set m = m + power(rem, x) Set n as n/ 10 End Loop Return m; End Step 4-> Declare main int main(int argc, char const *argv[]) Declare and set n = 1634 Call function Armstrong and check if the value is equal Print “it is armstrong number End if Else Print number isn't an armstrong number End STOP
Example
#include <stdio.h> int power(int a, int b){ int power =1; while(b>0){ power *= a; b--; } return power; } int count(int n){ int i=0; while(n!=0){ i++; n = n/10; } return i; } int armstrong(int n){ int x = count(n); int rem = 0, m=0; while(n){ rem = n %10; m += power(rem, x); n /= 10; } return m; } int main(int argc, char const *argv[]){ int n = 1634; if(n == armstrong(n)){ printf("%d is an armstrong number
",n); } else printf("%d isn't an armstrong number
",n); return 0; }
Output
1634 is an armstrong number
- Related Articles
- Java program to print the Armstrong numbers between two numbers
- Golang Program to Check For Armstrong Number
- C++ Program to Check Armstrong Number
- C Program to Check Armstrong Number?
- Java Program to Display Armstrong Numbers Between Intervals Using Function
- Swift Program to display Armstrong Numbers Between Intervals Using Function
- Haskell Program to Display Armstrong Numbers Between Intervals Using Function
- Armstrong Numbers between two integers?
- Armstrong numbers between a range - JavaScript
- Program for Fibonacci numbers in C
- C++ Program to Display Armstrong Number Between Two Intervals
- How to generate armstrong numbers in Python?
- Write a program in Python to filter armstrong numbers in a given series
- How to print Narcissistic(Armstrong) Numbers with Python?
- Python Program to Check Armstrong Number

Advertisements