Isn't passing all the test cases

#include <bits/stdc++.h>
using namespace std;

int main() {

int num1, num2, i, num, digit, sum, count;
cin >> num1;
cin >> num2;

if (num1 > num2) {
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
}

for(i = num1; i <= num2; i++) {
count = 0;

        num = i;

while(num>0) {
        ++count;
        num /= 10;
}
      sum = 0;

     num = i;
    

while(num>0) {
  digit = num % 10;
  sum = sum + pow(digit,count);
  num =num/10;
}


if(sum == i) {
  cout << sum;
}

}
return 0;
}

hi @abhijee0123
cout << sum << endl; print new line after printing each sum