We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Thursday, July 9, 2015

String Reverse without predefined function in C#

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter any String: ");
            string input = Console.ReadLine();
            string str = "";

            for (int i = input.Length - 1; i >= 0; i--)
            {
                if (input[i] == ' ')
                {
                    for (int j = str.Length - 1; j >= 0; j--)
                    {
                        Console.Write(str[j]);
                    }
                    if (i != 0)
                    {
                        Console.Write(" ");
                        str = "";
                    }
                }
                else
                {
                    str += input[i];
                    if (i == 0)
                        for (int j = str.Length - 1; j >= 0; j--)
                        {
                            Console.Write(str[j]);
                        }
                }
                }

            Console.ReadLine();
        }


    }

 
Output:

No comments: