-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Saturday, 23 May 2015

Finding Armstrong number in C++

Today I am here with a new program that will input a number from the user and determine whether it's Armstrong number or not.

Armstrong number 

  1. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Write a program to find all Armstrong number in the range of 0 and 999(reference taken from http://www.cs.mtu.edu)
  2. So, below is the source code of this program.

  1. Source code



Armstrong number in C++

Output


Explanation:

In this program,we will input a number from the user.

Line # 11:

                 At this line, there is a loop that explains that if the user enters "0", this loop would be terminated.

Line # 13:

                  It will take the modulus(remainder) of the number being entered by the user.

Line # 14:

                Now it will divide the given number by 10.

Line # 18:

                If the given result would be equal to check(or given number),then it will display that it is an Armstrong number other it will display that it is not an Armstrong number.

If you have still any ambiguity in understanding the logic of this program, then feel free to contact me at "G.A.Mujtaba11@gmail.com".


No comments:

Post a Comment