Reverse String Program in C#
Advertisements
Reverse a String Program in C#
To reverse any string we no need any new concept just apply same concept like C and C++ Program.
Formula
Remainder = Number % 10; Reverse = (Reverse * 10) + remainder; Number = Number / 10;
Reverse a String Program in C#
using System;
namespace reverseString
{
class Program
{
static void Main(string[] args)
{
string str = "", reverse = "";
int Length = 0;
Console.WriteLine("Enter any String: ");
//Getting String(word) from Console
str = Console.ReadLine();
//Calculate length of string str
Length = str.Length - 1;
while(Length>=0)
{
reverse = reverse + str[Length];
Length--;
}
//Displaying the reverse string
Console.WriteLine("Reverse String is: {0}",reverse);
Console.ReadLine();
}
}
}
Output
Enter any String: Raj Reverse String is: jaR
Output
Enter any String: Hitesh Reverse String is: hsetiH
Google Advertisment
