Friday, 26 January 2018

Reverse string without using in-built function

a) string str = "I am Ashish Verma";

out- amreV hsihsA ma I;

Exp -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StringReverse
{
    class Program
    {
        static public string ReverseString(string stringTobeReverse)
        {
            string reverseStr = string.Empty;
            for (int i = stringTobeReverse.Length-1 ; i >= 0 ; i--)
            {
                reverseStr += stringTobeReverse[i];
            }
            return reverseStr;
        }

        static void Main(string[] args)
        {
           string str = "I am Ashish Verma";

           string s=  ReverseString(str);
            Console.WriteLine(s);
            Console.ReadLine();
           //output  amreV hsihsA ma I
        }
    }
}



No comments:

Post a Comment