Why is this code(is armstrong number) not giving any output?

#include
#include
using namespace std;
int main() {
int n,count=0;
int sum=0,res,val,dgt,chk;
cin>>n;
val=n;
chk=n;
while(n>0)
{
val=val/10;
count=count+1;
}

while(n>0)
  { 
      dgt=n%10;
      n=n/10;
      res=pow(dgt,count);
      sum=sum+res;

  }
if(sum==chk)
{
    cout<<"true";
}
else
cout<<"false";
return 0;

}

@S19LPDWK0093 Please copy and save the code in coding blocks ide and share its link.

@S19LPDWK0093 You code is not giving any output because it is getting into an infinite loop at line number 10 as n is not being decremented/changed within the loop.Also there is no need for that while loop and count variable as armstrong number is a number whose sum of cube of digits is same as that number.

ok ty replaced val with n and armstrong number is not the number whose sum of cube of digits is same as that number , it depend on how many digits , for 2-digit square, for 3-digit cube

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.