Dry Run the given code:
int num,r,sum=0,t;
cin >> num;
for(t=num; num!=0; num=num/10)
{
r=num % 10;
cout<<r<<endl;
sum=sum*10+r;
cout<<sum<<endl;
}
It will prompt the user to enter value of num on screen and will continually divide num by 10 in a for loop and printing mode value of num and 10.the mode will be stored in variable r.The process will repeat till num is zero that is when the loop will be exited.
It will also print sum which is accumulated from the formula sum=sum*10+r
Comments
Leave a comment