C Program to check a number is Armstrong or Not.

C Program to check a number is armstrong number or not?

If you are learning c language and trying out all the basic programs related to it. You will see the Armstrong number program in every book. It is a very important program from the placement and exam point of view.

If you know nothing about the C language. I will suggest you check this link first. Introduction to C Language.

Before getting directly to the code. let’s first understand what is an Armstrong number.

Armstrong Number-

Armstrong is a number whose sum of cube of every digit is equal to the number of itself.

Example of Armstrong number – 153 is an Armstrong number because of the cube of 1, 5, 3 and sum gives 153 numbers.

I hope to know you will be able to understand easily.

Method 1 – Armstrong Number Program

Output – Enter a three-digit integer: 154 154 is not an Armstrong number.

In the above program, we have taken the number from the user and using the loop has taken the digits and cubing them and adding to the result variable.

Method 2 – Armstrong Number –

In the second method, we will use functions to perform the task when they are called.

The output will be the same as in the above method.

In this method, we created a function named Armstrong and calculated the sum of the cube of digits in it.

After calculating the result, it is returned back to the main program and after that, the comparison is made and results are fetched.

Try the same program using a five-digit number Example – 35422 and comment down the answer you got.

Recommended Posts –

  1. Introduction to C language
  2. Structure of C program
  3. C Program to add two numbers
  4. C Program to reverse a number
  5. Difference between C and C ++.

For more details can check the website: Armstrong Number

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner