Tuesday, March 25, 2014

Final Review_14_18 (For loop, while loop, do while loop)

//==========================Ex 14============================
Ex 14.    Display all the numbers between 29 and 99.
                    {
                        for (int counter = 29; counter <= 99; counter++)
                        {
                            Console.WriteLine("Counter no: {0}", counter);
                        }
                    }

//==========================Ex 15(a)==========================
Ex 15.    Display all the even numbers between 29 and 99. (show two different ways)
                 {
                        for (int counter = 29; counter <= 99; counter++)
                        {
                            if (counter % 2 == 0)
                            {
                                Console.WriteLine("Counter Even No: {0}", counter);
                            }
                        }
                    }
 //==========================Ex 15(b)==========================
                   {
                        int counter = 29;
                        do
                        {
                            if (counter % 2 == 0)
                            {
                                Console.WriteLine("Counter Even No: {0}", counter);
                            }
                            counter++;
                        }while (counter <= 99);
                    }
//==========================Ex 16============================
Ex 16.    Display all the numbers between 87 and 47 in descending order
                 {
                        int counter = 87;
                        while (counter >= 47)
                        {
                            Console.WriteLine("Counter No: {0}", counter);
                            counter--;
                        }
                    }
//==========================Ex 17============================
Ex 17.    Use a nested for loop to display a box full of stars. There should be 7 lines of 9 stars each
                   {
                        for (int i = 0; i < 7; i++)
                        {
                            for (int j = 0; j < 9; j++)
                            {
                                Console.Write(" * ");
                            }
                            Console.WriteLine();
                        }
                        Console.ReadLine();
                    }
//==========================Ex 18============================
Ex 18.    Request two integers values R and C. R should be between 2 and 20 and indicates the number of rows (or lines) and C should be between 3 and 70 and indicates the number of columns. Display R lines of C stars per line.
              {
                        Console.Write("Enter row no between 2 to 20: ");
                        int row = Convert.ToInt32(Console.ReadLine());

                        Console.Write("Enter column no. between 3 to 70: ");
                        int column = Convert.ToInt32(Console.ReadLine());

                        for (int counter = 1; counter <= row; counter++)
                        {
                            for (int ct = 1; ct <= column; ct++)
                            {
                                Console.Write(" * ");
                            }
                            Console.WriteLine();
                        }
                    }

No comments:

Post a Comment