Loops and Functions In C#
This code is basically for the begineers who want to get a clear concept of loop and function.
This program will draw atriangle full of stars.Thiswill at first ask the user about how many lines of stars they want andaccordingly that many number of lines of stars forming a triangle willbe formed.
//Triangle full of star
using System;
class star
{
public static void space(int x)
{
for(int i=0 ; i <= x ; i++)
Console.Write(" ");
}
public static void Main()
{
int no=31;
Console.WriteLine("How many lines of star you want?");
int s=Int32.Parse(Console.ReadLine());
space(32);
Console.WriteLine("*");
for(int i=2;i<=s;i++)
{
space(no);
for(int k=1;k<=i+i-1;k++)
Console.Write("*");
no=no-1;
Console.WriteLine();
}
}
}












No comments yet... Be the first to leave a reply!