diff --git a/Day 1 Class Examples/example1/Program.cs b/Day 1 Class Examples/example1/Program.cs new file mode 100644 index 0000000..48b1b8d --- /dev/null +++ b/Day 1 Class Examples/example1/Program.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace example1 +{ + class Program + { + private int x; + protected int y; + public int z; + static void Main(string[] args) + { + Console.WriteLine("Hello world"); + //Test t = new Test(); + //t + string s = "hello, "; + s += "world"; + Console.WriteLine("hello, " + s + s + s + "some other string" + s + "something"); + Console.WriteLine("hello, {0.2} {1} {2} {3}", s, s, s, s); + } + } + + class Test : Program + { + + } +} diff --git a/Day 1 Class Examples/example2/Program.cs b/Day 1 Class Examples/example2/Program.cs new file mode 100644 index 0000000..e90b62d --- /dev/null +++ b/Day 1 Class Examples/example2/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace example2 +{ + class Program + { + static void Main(string[] args) + { + int n1, n2; + Console.WriteLine("Please enter 2 numbers"); + n1 = Int32.Parse(Console.ReadLine()); + n2 = Int32.Parse(Console.ReadLine()); + Console.WriteLine("{0} + {1} = {2}", n1, n2, n1 + n2); + Console.WriteLine("{0} * {1} = {2}", n1, n2, n1 * n2); + Console.WriteLine("{0} / {1} = {2}", n1, n2, n1 / n2); + Console.WriteLine("{0} - {1} = {2}", n1, n2, n1 - n2); + Console.Read(); + } + } +} diff --git a/Day 1 Class Examples/example3/Program.cs b/Day 1 Class Examples/example3/Program.cs new file mode 100644 index 0000000..5b9af75 --- /dev/null +++ b/Day 1 Class Examples/example3/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace example3 +{ + class Program + { + static void Main(string[] args) + { + int tal = 0; + string tmp; + Console.WriteLine("Please enter 5 numbers:"); + for (int i = 0; i < 5; i++) + { + tmp = Console.ReadLine(); + tal += Int32.Parse(tmp); + } + Console.WriteLine("Value of tal = {0}", tal); + } + } +} diff --git a/Day 1 Class Examples/example4/Program.cs b/Day 1 Class Examples/example4/Program.cs new file mode 100644 index 0000000..f19dab3 --- /dev/null +++ b/Day 1 Class Examples/example4/Program.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace example4 +{ + class Math + { + public int pow(int num, int power) + { + int tmp = 1; + for(int i = 0; i < power; i++) + { + tmp *= num; + } + return tmp; + } + + } + class Program + { + static void Main(string[] args) + { + int n2; + int n1; + Console.WriteLine("Please enter a number and a power:"); + n1 = Int32.Parse(Console.ReadLine()); + n2 = Int32.Parse(Console.ReadLine()); + Math m = new Math(); + Console.WriteLine("The value is {0}", m.pow(n1, n2)); + } + } +} diff --git a/Day 1 Class Examples/example5/Program.cs b/Day 1 Class Examples/example5/Program.cs new file mode 100644 index 0000000..f61eb02 --- /dev/null +++ b/Day 1 Class Examples/example5/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace example5 +{ + class Program + { + static int fact(int n) + { + if (n == 0) + return 1; + else + return n * fact(n - 1); + } + static void Main(string[] args) + { + Console.WriteLine("{0}", fact(3)); + } + } +}