Posted by : Sudhir Chekuri Saturday, 5 October 2013


Output required: Print a message to ask user to enter the number of rows based on which stars are printed.
In the first row there should be one star, In the second row 2 stars, In the third row 3 stars,... as shown in the below image.


C# Code for the above task

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleTasks
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter no. of rows");
            //taking no. of rows from user
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j < i; j++)
                { Console.Write("*"); }
                //for moving to second row
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

VB.NET Code for the above task

Module Module1

    Sub Main()
        
        Console.WriteLine("Enter no. of rows")
        'taking no. of rows from user
        Dim n As Integer = Convert.ToInt32(Console.ReadLine())
        For i = 0 To n - 1 Step 1
            For j = 0 To i Step 1
                Console.Write("*")
            Next
            Console.WriteLine("")
        Next
        Console.ReadKey()
    End Sub

End Module

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

Blog Archive

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -