C Program to Check Armstrong Number2 min read

In this C programming example, we will write a program to check Armstrong Number in C. We will start with Armstrong Number.

Before that, you should have knowledge of the following topics in C programming.


What is an Armstrong Number?

A number is said to be an Armstrong Number if even after the sum of its digits, where each digit is raised to the power of the number of digits is equal to the original number. For example 153, 371, 407, 9474, etc are Armstrong numbers.

Armstrong Number in Java

C Program to Check for Armstrong Number

This program checks Armstrong number for 3 digit numbers only, not more than 3 digits.

Output:

Enter the number: 371
371 is an Armstrong Number


C Program Check Armstrong Number of n number of digits

This number checks Armstrong Number for any number of digits. Armstrong Number finds the power of each digit to the number of digits present in that number such as:

Number: 1634
=1^4+6^4+3^4+4^4
=1+1296+81+256
=1634
The original Number and sum of the number are the same. Therefore, it is an Armstrong Number.

To make it simple, we have used one of the math functions, pow()provided by math.h library. The pow() takes two-digit, one the number whose power needs to be found and the other is the power itself.

Output:

Enter the number: 1634
1634 is an Armstrong Number

The programs first stored the number of digits present in the number by incrementing the n value so that it can be later used in calculating the power as shown in the program.


MORE

Java Program to find the sum of the Largest Forward Diagonal

in this tutorial, we will write a java program to find the sum of the Largest Forward Diagonal in an Arraylist (matrix). Java Program to …

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …