1. Reversing a sentence without reversing the words
using System;
namespace ReverseSentense
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Write the sentence to
reverse");
string input = Console.ReadLine();
string[] sentense = input.Split(' ');
string output = "";
for (int i = sentense.Length - 1; i >= 0; i--)
{
if (!string.IsNullOrEmpty(output))
output = output + " ";
output = output + sentense[i];
}
Console.WriteLine(output);
Console.ReadKey();
}
}
}
output :
2. Reversing a sentence with reversing the words in it.
using System;
namespace ReverseStringSentense
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string to
reverse");
string input = Console.ReadLine();
string[] sentense = input.Split(' ');
string output = string.Empty;
string temp = string.Empty;
for (int i = sentense.Length - 1; i >= 0; i--)
{
string s = sentense[i];
temp = string.Empty;
for (int j = s.Length - 1; j >= 0; j--)
{
temp = temp + s[j];
}
output = output +" "+ temp;
}
Console.WriteLine(output.TrimStart());
Console.ReadKey();
}
}
}
output :
3. Reversing a string alone with and without using inbuilt functions:
using System;
namespace ReversEntireString
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the srtring to
reverse");
string input = Console.ReadLine();
string output = "";
//foreach (char a in
input.Reverse().ToArray())
//{
// output = output + a;
//}
for (int i = input.Length-1; i >= 0; i--)
{
output = output + input[i];
}
Console.WriteLine(output);
Console.ReadLine();
}
}
}
Output :