Search Forum
(57415 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


              
Printable Version

Loops and Functions In C#
By Subrata Talukdar

This code is basically for the begineers who want to get a clear concept of loop and function.

This program will draw a triangle full of stars.This will at first ask the user about how many lines of stars they want and accordingly that many number of lines of stars forming a triangle will be 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();
  }
 }
}