Program in C++ To check whether the given number is Armstrong or not :
Armstrong Number: When a number is equal to the sum of the cube of each digit, then it is called an Armstrong Number.
Example: Number 153 is an Armstrong number because:
1 5 3
= 1*1*1 + 5*5*5 + 3*3*3
= 1 + 125 + 27
= 153 = Number, Hence it is Armstrong number.
The numbers 0, 1, 153, 370, 371 and 407 are some of the Armstrong numbers.
The numbers 0, 1, 153, 370, 371 and 407 are some of the Armstrong numbers.
There are various ways to check whether a number is Armstrong or not. The General algorithm for the program is given below :
Algorithm :
Step 1: Accept a number.
Step 2: Extract each digit and cube it and add it to a variable say sum.
Step 3
If the sum is equal to a number then display that the number is Armstrong
else display that the number is not Armstrong.
Step 3: Stop
Code 1 :
Code 2 :
If you have any doubt/questions related to Program, or if you want to give any suggestions, feel free to comment below. Don't forget to subscribe and share it with friends.
0 Comments