This program reverses digits of a number for eg 125 will be reversed to 521 but i dont get the while loop can anyone explain me how while loop is working here
#include <iostream>
using namespace std;
int reverseDigit(int num)
{
int result = 0;
bool isNegative=false;
if(num<0)
{
isNegative=true;
num*=-1;
}
while(num > 0) \\ please explain this loop
{
result = result*10 + num%10;
num /= 10;
}
if (isNegative)
{
result*=-1;
}
return result;
}
int main()
{
bool isNegative=false;
int amount;
cout<<"Enter the number to be reversed : ";
cin>>amount;
cout<< endl;
cout<<"The number reversed is : ";
cout << reverseDigit(amount) << endl;
}