class Program
{
static void Main(string[] args)
{
int i, j = 0;
Console.WriteLine("Enter a string ");
string s = Console.ReadLine();
Console.WriteLine();
for (i = 0; i < s.Length; i++)
{
if (s[i] == ' ')
{
j++;
}
}
string[] rev = new string[j + 1];
int t = j;
for (i = 0; i < s.Length; i++)
{
if (s[i] == ' ')
j--;
else
rev[j] = rev[j] + s[i];
}
for (i = 0; i <= t; i++)
{
Console.Write(rev[i] + " ");
}
Console.WriteLine();
Console.ReadLine();
}
}
Output:
No comments:
Post a Comment