Archive for the “Programming” Category

Once upon a time, in my early days of programming, an instructor in the computer course wanted to help me improve my programming techniques! She asked me whether I would write a program to sort numbers from 0 to 9 given in mixed order. Then, she went. Perhaps she thought it would take too long.

After thinking a second, or two, I run after her and asked if it would make a difference if I correctly display them on the screen. She, confidently, said “no”.

A few minutes later, I called her to see the result. Although she had a shock, she didn’t even wondered how I did it!

Despite it has nothing to do with the logic of real sorting algorithms, there are many lessons behind it. One is that “the result is more important!” You guess the others…

Here is a C# implementation of that funny sorting algorithm. You may read the real stuff in Wikipedia.

 

using System;
using System.Text;

namespace FunnySort
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] numbers = { 7, 3, 6, 2, 0, 8, 4, 1, 5, 9 };
            foreach (int number in numbers)
            {
                Console.CursorLeft = number * 3;
                Console.Write(number);
            }
            Console.ReadKey();
        }
    }
}

Tags: ,

Comments No Comments »

While writing a post (in Turkish) I recalled the old days. This is the C# (or modern) version of one of the sample codes, I made in a computer class, years ago. The original one was in BASIC and had four lines, though.

using System;
using System.Text;

namespace TimesTable
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.Clear();
      for(int i = 1; i <= 10; i++)
        for (int j = 1; j <= 10; j++)
        {
          Console.SetCursorPosition(
            ((i - 1) % 5) * 16,
            ((i - 1) / 5) * 11 + (j - 1));
          Console.Write(string.Format(
            "{0,2} x {1,2} = {2,3}", i, j, i * j));
        }
      Console.ReadKey();
    }
  }
}

Comments No Comments »