• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C » Armstrong Number in C
Next →
← Prev

What is an Armstrong Number in C language?

By Dinesh Thakur

In this Armstrong Number in C tutorial, we will write a C program for armstrong number.

An Armstrong number or Narcissistic number is an n-digit number equivalent to the sum of digits raised to the nth power of digits from the number. A few Armstrong numbers are: 0, 1, 2, 3, 153, 370, 407, 1634, 8208, etc.

Syntax for Armstrong number

abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + .... 

Let’s try to understand why 1634 is an Armstrong number.

Let’s example it using mathematical computation.

Example: 1634
1634 = (1)4 + (6)4 + (3)4 + (4)4
= 1 + 1296 + 81 + 256
= 1634

Pictorial Presentation:

Armstrong-number-in-CAlgorithm to check given number is Armstrong number or not

START
Step 1 → Take integer variable num.
Step 2 → Assign (num) value to the (temp) variable.
Step 3 → Split all digits of num by dividing it to base value 10. 
Step 4 → Find the nth power of each digit.
Step 5 → Add all digits values together.
Step 6 → If Sum equivalent to num print, It is an Armstrong number. 
Step 7 → If Sum not equivalent to num print, It is not an Armstrong Number.
STOP

Pseudocode for Armstrong number

Below is the procedure for armstrong number in C

temp = num
rem = 0
WHILE temp IS NOT 0
  rem ← temp modulo 10
  sum ← sum + power(rem, digits);
  divide temp by 10
END WHILE
  IF sum equivalent to num
    PRINT Armstrong Number
  ELSE
    PRINT not an Armstrong Number
END IF
end procedure

C Program for Armstrong Number

The implementation of the algorithm provides below. It is possible to alter the value of the num variable and implement and assess your program. We compute the number of digits within our program and calculate the sum of individual digits raise to the power number of digits. Whether this sum equals the input number, then the number will be the Armstrong number differently not.

/**
* C program to check Armstrong number
*/
#include<stdio.h>
int find_arm(int);
int power(int, int);
int main () {
  int num;
  printf("Enter any Number to Check its Armstrong Number or not :");
  scanf("%d", &num);
  if (find_arm(num) == 1)
   printf("%d is an Armstrong number.\n", num);
  else
   printf("%d isn't an Armstrong number.\n", num);
  return 0;
}
int find_arm(int num) {
  int sum = 0, temp;
  int rem, digits = 0;
  temp = num;
  while (temp != 0) {
   digits++;
   temp = temp/10;
  }
  temp = num;
  while (temp != 0) {
   rem = temp%10;
   sum = sum + power(rem, digits);
   temp = temp/10;
 }
  if (num == sum)
   return 1;
   else
   return 0;
}
int power(int num, int r) {
  int loop;
  int prime = 1;
  for (loop = 1; loop <= r; loop=loop+1)
   prime = prime * num;
   return prime;
}

Output of above program

armstrong number program in CHow it works:

This table Shows Exactly What Occurs at each iteration of the while loop (assuming the num = 1634):

Iteration remsumnum
After 1st iterationrem = 1634%10 = 4sum = 0 + (4)4 = 256num = 1634 / 10 = 163
After 2st iterationrem = 163%10 = 3sum = 256 + (3)4 = 337num = 163 / 10 = 16
After 3st iterationrem = 16%10 = 6sum = 337 + (6)4 = 1633num = 16 / 10 = 1
After 4st iterationrem = 1%10 = 1sum = 1633 + (1)4 = 1634num = 1 / 10 = 0

To print out all armstrong numbers between 1 and 1000.

#include<stdio.h>
#include<conio.h>
void main() {
  int c,t,temp,sum,num;
  printf("Armstrong numbers between 1 and 1000 : \n");
  printf ("Numbers like = cube(digit1) + cube(digit2) + cube(digit3) \n");
  printf("l53 = cube(1) + cube(5) + cube(3)");
  for (num=1; num<=1000; num++) {
    sum = 0; temp = num;
    while(temp>0) {
      t = temp%10;
      sum+= (t*t*t);
      temp = temp/10;
    }
    if (sum==num) { 
      printf ("\nNumber %d is armstrong number", num); 
    }
  }
   getch();
}

OUTPUT:

armstrong numbers

Explanation: In this program, we have to find all Armstrong numbers between 1 and 1000. For this, we firstly initialize (sum = 0) and temp = num = 1. Then we apply modulus operator(%) and various other operations to calculate new sum = sum + (t*t*t);. When we exit from for loop, we check whether the sum and number num is equal. If they are equal, then it is Armstrong’s number, and the value is printed.

You’ll also like:

  1. Armstrong Number In Python Language
  2. Difference Between Procedure Oriented Language and Object Oriented Language
  3. What is linear search in C language?
  4. Armstrong Number in Java Example
  5. Armstrong Number With in Range Java Example
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

C Programming

C Programming Tutorials

  • C - History
  • C - Anatomy
  • C - Constants
  • C - Identifiers
  • C - Data Types
  • C - Libraries File
  • C - Header Files
  • C - Basic Language
  • C - Data Types Sizes
  • C - Header Files Importance
  • C - Escape Sequences
  • C - Main() Purpose
  • C - Program Procedure
  • C - Control Statements
  • C - Enumeration Constant
  • C - Add numbers
  • C - Return Statement
  • C - Avoid Goto
  • C - Command Line Arguments
  • C - Switch Case
  • C - Switch Case Limitations
  • C - getchar() and putchar()
  • C - Iteration Statements
  • C - Pass by Value and Reference
  • C - Structures and Unions
  • C - Structure
  • C - Dynamic Memory
  • C - Fgets and Fputs Functions
  • C - Gets() and Puts() Functions
  • C - Armstrong Number
  • C - Storage Classes
  • C - Fibonacci Series
  • C - Precision Setting
  • C - const Parameters

C - Variable & It's Type

  • C - Variables
  • C - Variable Lifetime
  • C - Static Variable
  • C - Register Variable
  • C - Global Variables
  • C - Auto Variables
  • C - Local Variables

C - Operator & Expressions

  • C - Operator
  • C - Boolean Operators
  • C - Bitwise Operator
  • C - Arithmetic Operators
  • C - Modulus Operator
  • C - Ternary Operator
  • C - Expressions
  • C - Arithmetic Expressions

C - Array

  • C - Arrays
  • C - Array Types
  • C - Array Characteristics
  • C - Static Arrays
  • C - Global Arrays
  • C - 3D Arrays
  • C - Dynamic Arrays
  • C - Pointer to 3D Arrays
  • C - Array Elements Hold
  • C - Arrays as Function Parameters
  • C - Accessing Matrix Elements
  • C - File Handling
  • C - Matrix Multiplication
  • C - Dynamic Memory Allocation

C - Searching & Sorting

  • C - Data Structures
  • C - Linear Search
  • C - Bubble Sort
  • C - Merge Sort
  • C - Linked List
  • C - Insertion Sort
  • C - Binary Search
  • C - Selection Sort
  • C - Quick Sort

C - Functions

  • C - Functions
  • C - Functions Advantages
  • C - Void Functions
  • C - Function Call
  • C - Default Return Value
  • C - String functions

C - Pointer

  • C - Pointers
  • C - Type Casting Of Pointers
  • C - Pointer Advantages
  • C - Pointers Initialization
  • C - Vectors and Pointers

C - Differences

  • C - C Vs C++
  • C - Formal Args. Vs Actual Args.
  • C - Keywords Vs Identifiers
  • C - Strings Vs Character Arrays
  • C - Address Vs Dereference Operator
  • C - Goto Vs longjmp
  • C - Declaring Vs Defining Variable
  • C - String Vs Array
  • C - Call by Value Vs Reference
  • C - Structure Vs Union
  • C - For Vs While loops
  • C - Compiler Vs Interpreter

C - Programs

  • C Program Standard Deviation
  • C Program Calculate Tax
  • C Program Sum Series
  • C Program Merge Arrays
  • C Program Euclid’s Algorithm
  • C Program Print Weekdays
  • C Program Sum of Digits
  • C Program Print a list
  • C Program Print Pythagorean
  • C Program Quiz program
  • C Program Display Table
  • C Program Print Comma-Separated
  • C Program Prints Prime Numbers
  • C Program for Print Integer
  • C Program Count Number
  • C Program Print Color Name
  • C Program Print Odd Numbers
  • C Program Calculate area
  • C Program for a Menu
  • C Program Add Two Vectors
  • C Program Array Addresses
  • C Program Division by Zero Error
  • C Program Compare two Dates
  • C Program Tower of Hanoi
  • C Program return 3 Numbers
  • C Program for Prime Numbers
  • C Program for Factorial
  • C Program for Palindrome

Other Links

  • C Programming - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW