// armstrong number is a number = sum of cubes of its digit // ex: 153 = 1^3 + 5^3 + 3^3 --> 153 is an armstrong number //write a program to input two natural m and n, then find an display to screen all Armstrong numbers from m to n. #include<iostream> #include<math.h> using namespace std; int main() { int m, n; cout << "Enter a natural m: "; cin >> m; cout << "Enter a natural n: "; cin >> n; cout << "Armstrong numbers from " << m << " to " << n << " are: " << endl; int i = m; while(i <= n) { int num = i; int temp = num; int sum = 0; int cnt = 0; while(num > 0) { // dem so luong chu so trong num ++cnt; num /= 10; } num = temp; while(num != 0) { sum += pow(num%10, cnt); num /= 10; } if(sum == i) { cout << i << " "; } ++i; } return 0; }
m=0
n=10000
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)