C++ Program to check a number is Armstrong or not of 4 digits
In this program, you will learn how to check a number is Armstrong or not of 4 digits in C++.
Some list of Armstrong numbers of 4 digts : 1634, 8208, 9474
Example: How to check a number is Armstrong or not of 4 digits in C++.
#include<iostream>
using namespace std;
int main() {
int n, num, r, rev = 0;
cout << "Enter a number:";
cin >> n;
num = n;
while (n > 0) {
r = n % 10;
rev = rev + r * r * r * r;
n = n / 10;
}
if (rev == num) {
cout << "Number is Armstrong:" << num;
} else {
cout << "Number is not Armstrong:" << num;
}
return 0;
}
Output:
Enter a number:1634
Number is Armstrong:1634