Answer to Question #272286 in C# for chi

Question #272286

Write a program which produces the given sequences numbers (in alternate arrangement and reverse order of the problem no. 2) using the three

looping statements: 5, 1, 4, 2, 3, 3, 2, 4, 1, 5,


1st Solution – using for loop

2nd Solution – using while loop

3rd Solution-­‐ using do while loop


1
Expert's answer
2021-11-30T18:19:43-0500
internal class Program
    {
        static void Main(string[] args)
        {
            string array = GetReverseArrayUsingFor(("5, 1, 4, 2, 3").Split(',').ToArray());
            Console.WriteLine($"Use for: {array}");


            array = GetReverseArrayUsingWhile(("5, 1, 4, 2, 3").Split(',').ToArray());
            Console.WriteLine($"Use while: {array}");


            array = GetReverseArrayUsingDoWhile(("5, 1, 4, 2, 3").Split(',').ToArray());
            Console.WriteLine($"Use do while: {array}");


            Console.ReadKey();
        }
        static string GetReverseArrayUsingFor(string[] array)
        {
            string result = "";
            for (int i = array.Count()-1; i >= 0; i--)
            {
                result += array[i]+",";
            }
            return result;
        }
        static string GetReverseArrayUsingWhile(string[] array)
        {
            string result = "";
            int i = array.Count()-1;
            while (i>=0)
            {
                result += array[i] + ",";
                i--;
            }
            return result;
        }
        static string GetReverseArrayUsingDoWhile(string[] array)
        {
            string result = "";
            int i = array.Count() - 1;
            do
            {
                result += array[i] + ",";
                i--;
            } while (i>=0);
            return result;
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS