Q:

Write a C# Sharp program to create a string like "aababcabcd" from a given string "abcd"

0

Write a C# Sharp program to create a string like "aababcabcd" from a given string "abcd"

Sample Output:

aababcabcd
aababc
a

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(test("abcd"));
            Console.WriteLine(test("abc"));
            Console.WriteLine(test("a"));
            Console.ReadLine();
        }
        public static string test(string str)
        {
            var result = string.Empty;
            for (var i = 0; i < str.Length; i++)
            {
                result += str.Substring(0, i + 1);
            }
            return result;
        }
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now