Answer to Question #284395 in C# for Kim

Question #284395

Using the while ( ), do - while (), and for ( ) loops, generate the following screen


output:


Sample output


Series generated using while ( )


1 1 1 2 4 8 3 9 27


Series generated using do-while ( )


1 2 3 1 4 9 1 8 27


Series generated using for ( )


3 9 27 8 4 2 1 1 1


1
Expert's answer
2022-01-05T08:13:52-0500
using System;

namespace Series_with_for_and_while
{
    internal class Program
    {
        public static void Main(string[] args)
        {
           // Series generated using while ( )
           // 1 1 1 2 4 8 3 9 27
            int i = 1;
            while (i != 4)
            {
                Console.Write(Math.Pow(i,1) + " ");
                Console.Write(Math.Pow(i,2) + " ");
                Console.Write(Math.Pow(i,3) + " ");
                i++;
            }
            i = 1;
            Console.WriteLine("\n");
            
            // Series generated using do-while ( )
            // 1 2 3 1 4 9 1 8 27
            do
            {
                Console.Write(Math.Pow(1,i) + " ");
                Console.Write(Math.Pow(2,i) + " ");
                Console.Write(Math.Pow(3,i) + " ");
                i++;
            } while (i != 4);
            Console.WriteLine("\n");
            
            // Series generated using for ( )
            // 3 9 27 8 4 2 1 1 1
            
            for (int j = 3; j > 0; j--)
            {
                if (j % 2 != 0)
                {
                    Console.Write(Math.Pow(j, j-j+1) + " ");
                    Console.Write(Math.Pow(j, j-j+2) + " ");
                    Console.Write(Math.Pow(j, j-j+3) + " ");
                }
                else
                {
                    Console.Write(Math.Pow(j, 3) + " ");
                    Console.Write(Math.Pow(j, 2) + " ");
                    Console.Write(Math.Pow(j, 1) + " ");
                }
            }
        }
    }
}

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