C++ Program to check a number is Armstrong or not using the function
In this Program, You will learn how to check a number is Armstrong or not using the function in C++.
Some list of Armstrong numbers: 153, 370, 371, 407
Example: How to check a number is Armstrong or not using the function in C++.
#include<iostream>
using namespace std;
int checkNumber(int n) {
int r, rev = 0;
while (n > 0) {
r = n % 10;
rev = rev + r * r*r;
n = n / 10;
}
return rev;
}
int main() {
int n, num;
cout << "Enter a number:";
cin>>n;
num = checkNumber(n);
if (num == n) {
cout << "Number is ArmStrong:" << n;
} else {
cout << "The Number is not ArmStrong :" << n;
}
return 0;
}
Output:
Enter a number:153
Number is ArmStrong:153