Home  >  Article  >  php教程  >  php实现俄罗斯乘法实例

php实现俄罗斯乘法实例

WBOY
WBOYOriginal
2016-06-06 20:07:091022browse

这篇文章主要介绍了php实现俄罗斯乘法,实例分析了俄罗斯乘法的原理与代码实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了php实现俄罗斯乘法的方法。分享给大家供大家参考。具体分析如下:

一、概述:

俄罗斯乘法是一种计算两数相乘的算法。
举例如下:
计算 35*72
过程
35 72
17 144
8 288
4 576
2 1152
1 2304
从上到下,对每一行,,若左边的数字若为奇数,则将右边的数字取出,累加。
72+144+2304=2520
累加的结果2520即为乘积。

二、实现代码:

> 1; return $n ? russian($m, $n, $res) : $res; } echo russian(7, 8);

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn