Dinesh B

Dinesh B

  • NA
  • 117
  • 40.7k

Reverse the individual words in a sentence

Nov 12 2015 10:57 PM
By using for loop and if clause we can reverse the individual words in a sentence.
This program is in c#
Class Program
{
static void main(string[] args)
{
Int count=0,i,j;
Console.writeline("Enter the string");
String s = convert.Tostring(console.readline());
for(i=0;i<s.length;i++)
{
if(s[i]!=' ')
{
Count ++;
}
else
{
for(j =i-1;j>=i-count;j--)
{
console.write(s[j]);
}
Count =0;
Console.write(" ");
}}
Console.readline();
}}}
Note : while entering the words give a space after the last word.
The o/p will be correctly display

Answers (8)