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

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More

Inverted Half Pyramid Pattern of Alphabets in C

In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More