Q6 write a windows application to find out the reverse of any given number by the user.
Reverse number means 123 is 321. The form for this application looks like as follows:
Here textbox accept number and first it will be converted into integer number and assigned to the variable no. the code is as follows:
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
MessageBox.Show("Reverse of number is: "+rev,"Reverse Number");
We have declared a variables no, rev=0, r;
Here we have used a while loop. Here we have used the condition no>0 means loop will be continued while the value of no variable is greater than 0. Inside the loop, first of all we have to calculate the remainder of the no then assigned to the r variable. Because when we use no%10 ; this will give the last digit of the number. After that we have used the rev*10+r; here we add the value of r with rev*10 and assign to rev. now we have to get the next digit so that we have used the no/10 and assign it to no. This loop will be continued till the condition will not become false.
The output is as follows: