I have tried to print Armstrong number between 100 and 1000; my code with pow() function print all numbers except 153. But when I tried to run the code temp*temp*temp
it gives all numbers including 153. How?
#include<iostream>
#include <math.h>
using namespace std;
int main() {
int lower, upper;
cout << "enter the lower and upper bound number";
cin >> lower >> upper;
cout<< "armstrong number are " << endl;
for(int num = lower; num <= upper; num++) {
int sum = 0, num1 =num,temp;
while(num1 != 0) {
temp = num1 % 10;
// sum = sum + temp * temp * temp; [this gives a correct result]
sum = sum + pow(temp,3);
num1 = num1 / 10;
}
if(num == sum)
cout << num << endl;1
}
return 0;
}