- Back to Home »
- C#.NET , VB.NET »
- C#, VB.NET Console Application task - Print stars based on the given input by the user
Posted by :
Sudhir Chekuri
Saturday, 5 October 2013
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