Skip to content

Instantly share code, notes, and snippets.

@Shaun420
Created June 10, 2024 07:53
Show Gist options
  • Save Shaun420/1bc5bcec7f1ed0ce0f21404cee81f50a to your computer and use it in GitHub Desktop.
Save Shaun420/1bc5bcec7f1ed0ce0f21404cee81f50a to your computer and use it in GitHub Desktop.
C# program code to reverse the words in a sentence keeping their position same.
string pangram = "The quick brown fox jumps over the lazy dog";
string[] words = pangram.Split(" ");
string answer = "";
string reverse = "";
char[] charArray;
for (int i = 0; i < words.Length; i++) {
charArray = words[i].ToCharArray();
Array.Reverse(charArray);
reverse = new string(charArray);
words[i] = reverse;
}
answer = string.Join(" ", words);
Console.WriteLine(answer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment