Changes in code

#include
using namespace std;

int main() {
int origNum,num,rem,count=0;
int sum=0;
cin>>origNum;
num=origNum;
while(num!=0){
rem=num%10;
num/=10;
count++;

}if(count==3){
	num==origNum;
	while(num!=0){
		rem=num%10;
		sum+=rem*rem*rem;
		num/=10;
	}
}else if(count==4){
	num==origNum;
	while(num!=0){
		rem=num%10;
		sum+=rem*rem*rem*rem;
		num/=10;
	}
}
if(sum==origNum){
	cout<<"true";
}else{
	cout<<"false";
}
return 0;

}

@neelrai906
What if n=5,6,7,…

give suggestion for code changes and function approach for a common ‘n’

rather than multiply just raise rem to power n. ie sum += pow(rem,n)

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.