Answer to Question #273708 in C# for chi

Question #273708

Write a program that produces the given sequence nos. (in alternate arrangement) using

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


1st Solution – using for loop

2nd Solution – using

while loop

3rd Solution-­‐ using do while loop


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


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


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


            Console.ReadKey();
        }
        static string UsingFor(string[] array)
        {
            string result = "";
            for (int i = array.Count()-1; i >= 0; i--)
            {
                result += array[i]+",";
            }
            return result;
        }
        static string UsingWhile(string[] array)
        {
            string result = "";
            int i = array.Count()-1;
            while (i>=0)
            {
                result += array[i] + ",";
                i--;
            }
            return result;
        }
        static string UsingDoWhile(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