1. Reverse a Number in C#
- using System;
-
- namespace ReverseNo
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter a No. to reverse");
- int Number = int.Parse(Console.ReadLine());
- int Reverse = 0;
- while(Number>0)
- {
- int remainder = Number % 10;
- Reverse = (Reverse * 10) + remainder;
- Number = Number / 10;
- }
- Console.WriteLine("Reverse No. is {0}",Reverse);
- Console.ReadLine();
- }
- }
- }
Preview:
2. Reverse a String in C#
- using System;
-
- namespace reverseString
- {
- class Program
- {
- static void Main(string[] args)
- {
- string str = "", reverse = "";
- int Length = 0;
- Console.WriteLine("Enter a Word");
-
- str = Console.ReadLine();
-
- Length = str.Length - 1;
- while(Length>=0)
- {
- reverse = reverse + str[Length];
- Length--;
- }
-
- Console.WriteLine("Reverse word is {0}",reverse);
- Console.ReadLine();
- }
- }
- }
Preview:
Hope you like it. Thanks.