Bar chart displaying app. - CSharp Language Basics

CSharp examples for Language Basics:for

Description

Bar chart displaying app.

Demo Code

using System;//from   ww w.j a  v a  2s  .  c  om
class BarChart
{
   static void Main()
   {
      int[] array = {2, 0, 1, 0, 0, 0, 1, 2, 4, 2, 1}; // distribution
      Console.WriteLine("Grade distribution:");
      for (var counter = 0; counter < array.Length; ++counter)
      {
         // output bar labels ("00-09: ", ..., "90-99: ", "100: ")
         if (counter == 10)
         {
            Console.Write("  100: ");
         }
         else
         {
            Console.Write($"{counter * 10:D2}-{counter * 10 + 9:D2}: ");
         }
         // display bar of asterisks
         for (var stars = 0; stars < array[counter]; ++stars)
         {
            Console.Write("*");
         }
         Console.WriteLine(); // start a new line of output
      }
   }
}

Result


Related Tutorials