From 1b01f99fd0e5aa67fd9d25dd715b0e5fd5a5b632 Mon Sep 17 00:00:00 2001 From: "Md. Al Jobaed" Date: Wed, 28 Mar 2018 20:32:28 +0600 Subject: [PATCH] Add files via upload --- .../Day17MoreExceptions/Program.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 30_Days-of_Code_Challenges/Day17MoreExceptions/Program.cs diff --git a/30_Days-of_Code_Challenges/Day17MoreExceptions/Program.cs b/30_Days-of_Code_Challenges/Day17MoreExceptions/Program.cs new file mode 100644 index 0000000..1c573bd --- /dev/null +++ b/30_Days-of_Code_Challenges/Day17MoreExceptions/Program.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Day17MoreExceptions +{ + class Program + { + static void Main(string[] args) + { + Calculator c = new Calculator(); + Console.WriteLine(c.power(3, 5)); + Console.WriteLine(Math.Pow(3, 5 )); + Console.ReadKey(); + } + } + class Calculator + { + public int power(int n, int p) + { + int result = 1; + if (n < 0 || p < 0) + { + throw new Exception("n and p should be non-negative"); + } + else + { + for (int i = 1; i <= p; i++) + { + result *= n; + } + } + + return result; + } + } +}