Difficulty in forming nested loop for reversal of number

#include
#include<stdlib.h>
using namespace std;
int main()
{
int ans=0,count=0,n;
cin>>n;
int temp=n;
while(n!=0)
{
n=n%10;
n=n/10;
count+=1;
}

while(temp!=0)

{
int val=temp%10;
temp=temp/10;

for(int i=count;;i--)      // difficulty here. How to 
{                                             make it work for reversing?
  for(int j=1;j<=i;i++)
  {
     val=10*val;

  }
  break;
}
ans=ans+val;

}
cout<<ans<<endl;

return 0;

}

hey @ysurange1998 there were couple of mistakes in your code

  1. you dont need to do n = n%10 in the first while loop, if you do this it will always give count = 1
  2. in the second while loop instead of i use, count to control loop variable j and decrement count every turn
    Here is your code after the modifications:
    https://ide.codingblocks.com/s/186568

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.