A number in which the sum of cube of its individual digits is equal to the number itself is called Armstrong numberFor Example: 1^3 + 5^3 + 3^3 = 153
4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an Armstrong number.
C++ program which takes input a number and check whether it is Armstrong Number or not
Note: Program can be coded in more than one ways above program is very simple so any one can understand the logic of program.
Recommended: Change program logic and do experiment with it for fast learning.
Image view of the program click on image to view large
|Find Armstrong number in c++ code|
Concept Used: for loop, if-else statement
- To make logic firstly concept about Armstrong number should be very clear
- We took some variables in which we take input, make calculations and produce results
- Program take input number in variable num and store it in check variable
- In for loop we take mod of num with 10 and stores it in variable Armstrong then we divide it with 10(below dry running will make more clear the working)
- Then we take cubes of Armstrong variable and add it into result variable
- When num=0; then for loop break after for loop using if else statement we test if our result equals to check variable then number is Armstrong else not.
Dry Running The Armstrong number Code:
153 is an Armstrong Number
More C++ Programs Examples: