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:

reverse-number

Here textbox accept number and first it will be converted into integer number and assigned to the variable no. the code is as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CReverse
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int no,rev=0,r;
no=Convert.ToInt32(textBox1.Text);

while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
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:

reverse-number