Created
June 10, 2024 07:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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