Reversing Set of Numbers in C#
Submitted by janobe on Saturday, May 25, 2019 - 22:08.
In this tutorial, I will teach you how to reverse a set of numbers using C#. This procedure illustrates how to reverse any given numbers in a textbox and it will display in the listbox. Hope this simple program will help to solve your current problem. Follow the step by step guide to see how it works.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.Step 2
Do the form just like shown below.Step 3
Press F7 to open the code editor. In the code editor, create a method to reverse a given number.- private void reverse_numbers(int given_numbers)
- {
- int straight_numbers, reverse_number;
- reverse_number = 0;
- try
- {
- straight_numbers = given_numbers;
- while (straight_numbers > 0)
- {
- int remainder = straight_numbers % 10;
- reverse_number = (reverse_number * 10) + remainder;
- straight_numbers = straight_numbers / 10;
- }
- listBox1.Items.Clear();
- listBox1.Items.Add(reverse_number);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
Step 4
Call the method that you have created to execute when the button is clicked.- private void button1_Click(object sender, EventArgs e)
- {
- reverse_numbers(int.Parse(textBox1.Text));
- }
Add new comment
- 112 views