Reverse String using C#
using System;
//Input- My name is Sachin
//Expected output- yM eman si nihcaS
public class HelloWorld
{
public static void Main(string[] args)
{
string input = "My name is Sachin";
string[] words = input.Split(' ');
string result = "";
foreach (string word in words)
{
char[] chars = word.ToCharArray();
Array.Reverse(chars);
result += new string(chars) + " ";
}
// Trim the extra space at the end
result = result.TrimEnd();
Console.WriteLine(result);
}
}
Comments
Post a Comment