Armstrong Number in C++ Using While Loop

Armstrong number program in c++. This program will help you to find the armstrong number in c++. These are basic set program in every programming language for beginners.

#include <iostream>
using namespace std;
int main() 
{
int num, num1, rem, result = 0;
cout << "Enter the number";
cin >> num;
num1 = num;
while (num1 != 0)
{
rem = num1 % 10;
result += rem * rem * rem;
num1 /= 10;
}
if (result == num)
cout << num << " is Armstrong number";
else
cout << num << " is not Armstrong number";
return 0;
}

 

Output:

Enter the number 567

567 is not Armstrong number

Armstrong Number in C++

A number equal to the sum of its digits’ cubes is known as an Armstrong number. 

An Armstrong three-digit number is an integer in which the total of its digits’ cubes equals the number itself. 

371 is an Armstrong number, for example, since 3**3 + 7**3 + 1**3 Equals 371.

While Loop Definition in C++

A while loop’s fundamental feature is that it will repeat a series of instructions based on a condition. 

The code inside the loop will keep running as long as the loop returns a boolean value of true. 

When we don’t know how many times a piece of code has to be performed, we employ this type of loop. 

The condition is assessed first in a while loop, and if it returns true, the statements within the while loop are executed;

this is continued until the condition returns false. 

When the condition returns false, the control exits the loop and proceeds to the next statement in the program after the while loop.

If Else Statement in C++

If a particular condition is true, the if/else statement executes a block of code. 

If the condition is not met, another piece of code can be run. 

The if/else statement is a type of “Conditional” Statement in JavaScript, which is used to conduct different actions based on distinct situations.

The flowchart below shows that if the condition is true, one block of statements is run, but if the condition is false, a separate series of statements is executed within the otherwise clause.