CSharp Algorithm - Replace multiplication operator with a method

/*

Author: Jiangong SUN

*/


How to replace multiplication operation with a method? For example, you have two integers as method entries, and you will get a result of their multiplication.

You need just another point of view as to this problem. You can have a for loop for iterating one parameter, and add another parameter to variable result in this loop.

Here is the implementation.

        private static int Multiplication(int x, int y)
        {
            int result = 0;
            for (int i = 0; i < x; i++)
            {
                result += y;
            }
            return result;
        }

I hope this article can do help to you! Enjoy coding!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章