Home > Backend Development > PHP Tutorial > PHP interview question: These five coupons are 50, 40, 30, 20, 1. The order amount is X yuan. How many coupons can be returned using a method?

PHP interview question: These five coupons are 50, 40, 30, 20, 1. The order amount is X yuan. How many coupons can be returned using a method?

WBOY
Release: 2016-07-28 08:29:27
Original
918 people have browsed it

First of all, I excluded the order amount that was not an integer because the interviewer only gave me 7 minutes.

mou(99);//Call the following method here

function mou($x){

$array = array{50,40,30,20,1};

$temp = 0 ;

$j = $x ;

for($i=0;$

{

$temp = $temp+foor($j/$array [$i]);

$j = $j%$array[$i];

}

echo "A total of ". $temp." coupons";

return $temp;

}

?>

This method is simply used to find a model. I hope some experts can give me a better method. Just reply directly

The above introduces the PHP interview questions: these five coupons are 50, 40, 30, 20, 1, the order amount is X yuan, how many coupons are returned using the method, including the content, I hope you are interested in the PHP tutorial Friends help.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template