n=num;
while(num!=0)
{
d=num%10;
rev=rev*10+d;
num=num/10;
}
First the above should be the correct way of writing this, last two statements must be included in the while loop considering 'rev' and 'd' are declared, now we store the number 'num' in another variable in this program as for controlling this while loop we constantly change the value of 'num' till it has 0 inside it(i.e., till we get all the numbers out in 'd' one by one and given to 'rev' in reverse order) So we must store it somewhere else if we don't want to lose it. Also we should assign rev = 0 because if we only declare it as (int rev) then it might have some garbage value and show us incorrect result.