Answer to Question #273492 in C# for chi

Question #273492

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:19:12-0500
using System;
using System.Collections.Generic;


namespace App
{
    class Program
    {




        public static void Main()
        {
            int i,j;
            Console.WriteLine("using - for loop");
            for (i = 1, j = 5; i < 6; i++, j--)
            {
                if (i == 1)
                {
                    Console.Write("{0},{1}", i, j);
                }
                else
                {
                    Console.Write(",{0},{1}", i, j);
                }


            }
            Console.WriteLine("\n\nusing - while loop");
            i = 0;
            j = 5;
            while (++i < 6)
            {
                if (i == 1)
                {
                    Console.Write("{0},{1}", i, j);
                }
                else
                {
                    Console.Write(",{0},{1}", i, j);
                }
                j--;
            }
            Console.WriteLine("\n\nusing - do while loop");
            i=1;
            j = 5;
            do
            {
                if (i == 1)
                {
                    Console.Write("{0},{1}", i, j);
                }
                else
                {
                    Console.Write(",{0},{1}", i, j);
                }
                j--;
            } while (++i < 6);


            Console.ReadLine();
        }
    }
}

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
APPROVED BY CLIENTS