Unable to satisfy all test cases

#include<iostream

using namespace std;

int main() {

long n1;
cin>> n1;
int p =0;           // no. of digits
int num = 0;

// for counting no of digits

while(n1>0){
	int r = n1%10;
	p++;
	n1 = n1/10;
}

//to check for armstrong no.

while(n1>0){
	int r = n1%10;
	num = num + r^p;
	n1 = n1/10;
}

if(n1==num){
	cout<<"true"<<endl;
}
else{
	cout<<"false"<<endl;
}
 
return 0;

}

// Kindly correct my mistake as the code given above is not satisfying all test cases.

hello @arshia27
pls save ur code at cb ide and share its link with me

This is the link for the code. It is giving same output for all input values

check now->

Yes sir , now it is working fine. Thank you

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.