Friday, January 22, 2016

Problem-of-apollonius solver

This is a problem-of-apollonius solver. This program finds all 8 possible circles touching the three given circles.

All you need to do is just to give 3 circles. Then this program finds all circles touching the given circles.


Download the program (This is a C# program. You need to compile it locally,):
https://github.com/lechatthecat/ApolloniusCirclesDrawer

The essence of the code is described in Rosetta code:
http://rosettacode.org/wiki/Problem_of_Apollonius#C.23

About why this calculation finding the solution circles, read algebraic solution, probelm of apollonius, Wikipedia.

Monday, January 18, 2016

Get the current directory

using System;
using System.Data.OleDb;

namespace AccessTest
{
    class Program
    {
        static void Main(string[] args)
        {
        string a = System.IO.Directory.GetCurrentDirectory();
        Console.WriteLine(a);

        }
    }
}

Saturday, January 16, 2016

FizzBuzz written by C#

using System;

class Program
{
    static void Main(string[] args)
    {
        for(int i = 1; i <= 299; i++ )
        {
            if (i % 3 == 0 && i % 5 == 0)
            {
                Console.WriteLine("FizzBuzz");
                continue;
            }

            if( i % 3 == 0 )
            {
                Console.WriteLine("Fizz");
                continue;
            }
            else if(i % 5 == 0)
            {
                Console.WriteLine("Buzz");
                continue;
            }
         

            Console.WriteLine(i);
        }

        Console.ReadKey();
    }
}

Saturday, January 9, 2016

4 ways calculator

//If you want to stop this program, input "abc" and hit the enter.
using System.IO;
using System;


class Program
{
    static void Main()
    {
        while(true){
            Console.WriteLine("Please enter the first number:");

            string Num1 = Console.ReadLine();
            int d = 0;

                if(!int.TryParse(Num1, out d))
                {
                    Console.WriteLine("Please enter only numeric letters.");
                    return;
                }
 
                Console.WriteLine("Please enter the second number:");
                string Num2 = Console.ReadLine();
                int e = 0;

                if(!int.TryParse(Num2, out e)){
                    Console.WriteLine("Please enter only numeric letters.");
                    return;
                }

                int iNum1 = int.Parse(Num1);
                int iNum2 = int.Parse(Num2);

                int sum = iNum1 + iNum2;
                int difference = iNum1 - iNum2;
                long product = iNum1 * iNum2;
                double quotient = (double)iNum1 / (double)iNum2;

                Console.WriteLine();
                Console.WriteLine(Num1 + " + " + Num2 + " = " + sum);
                Console.WriteLine(Num1 + " - " + Num2 + " = " + difference);
                Console.WriteLine(Num1 + " x " + Num2 + " = " + product);
                Console.WriteLine(Num1 + " / " + Num2 + " = " + quotient + "\n");
        }
    }
}

Complex number, reciprocal calculator

using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Input the real part:");
        int x = int.Parse(Console.ReadLine());

        Console.WriteLine("Input the imaginary part:");
        int y = int.Parse(Console.ReadLine());

        double dx = (double)x;
        double dy = (double)y;
        double norm = dx * dx + dy * dy;
        Console.WriteLine("The reciprocal of " + x + "+" + y + "i is " + (dx/norm) + "+" + (-dy/norm) + "i");
    }
}

Circle area calculator

Written by C#.


using System.IO;
using System;
using System.Math;
class Program
{
    static void Main()
    {
        string radius = Console.ReadLine();
        long radius2;
   
            if(long.TryParse(radius, out radius2) == false)
            {
                Console.WriteLine("Not appropriate number.");
                return;
            }
   
       
        long diameter = radius2 * 2;
        double radius3 = radius2;
        double areaOfCircle = radius3 * radius3 * Math.PI;
   
        Console.WriteLine("Diameter: " + diameter);
        Console.WriteLine("The area of circle: " + areaOfCircle);
    }
}