This is contrary to the spirit of the assignment, but I would do it for kicks ...
Create your own class, overload the + operator to multiply.
Create your homework project; add your first project as a link. Write your code
return new SuperInt(x) + SuperInt(y);
Everyone else is going to change the beat or addition variations. Half of the children are going to publish the exact code returned by Google search anyway. At least in this way, you will be unique.
The purpose itself is simply an exercise in lateral thinking. Any sane person will use the * operator when working in .Net.
EDIT: If you really want to be a class clown, overload the * operator and implement it with bitwise operations and additions.
Additional answer # 1 (if you want to change your method signature ...) How about this?
static void Main(string[] args) { Console.WriteLine(string.Format("{0} * {1} = {2}", 5, 6, MultiplyNumbers(5, 6))); Console.WriteLine(string.Format("{0} * {1} = {2}", -5, 6, MultiplyNumbers(-5, 6))); Console.WriteLine(string.Format("{0} * {1} = {2}", -5, -6, MultiplyNumbers(-5, -6))); Console.WriteLine(string.Format("{0} * {1} = {2}", 5, 1, MultiplyNumbers(5, 1))); Console.Read(); } static double MultiplyNumbers(double x, double y) { return x / (1 / y); }
Outputs:
5 * 6 = 30 -5 * 6 = -30 -5 * -6 = 30 5 * 1 = 5
One straight line of code.
But still, if you take this approach, be prepared to argue a bit. It multiplies integers; by implicitly converting them to paired numbers in a call. Your question did not say that you can only use integers, just so that he would have to multiply two integers without using '*'.
EDIT: Since you say you cannot change the signature of MultiplyNumbers, you can execute it without doing this:
static uint MultiplyNumbers(uint x, uint y) { return MultiplyDouble(x, y); } static uint MultiplyDouble(double x, double y) { return Convert.ToUInt32(x / (1 / y)); }
Additional answer # 2 This is my favorite approach.
Take the values, send them to Google, analyze the result.
static uint MultiplyNumbers(uint x, uint y) { System.Net.WebClient myClient = new System.Net.WebClient(); string sData = myClient.DownloadString(string.Format("http://www.google.com/search?q={0}*{1}&btnG=Search",x,y)); string ans = x.ToString() + " * " + y.ToString() + " = "; int iBegin = sData.IndexOf(ans,50) + ans.Length ; int iEnd = sData.IndexOf('<',iBegin); return Convert.ToUInt32(sData.Substring(iBegin, iEnd - iBegin).Trim()); }