함수 harmean()

Jmnote (토론 | 기여)님의 2015년 2월 18일 (수) 22:33 판 (새 문서: 분류: 수학 ==PHP== category: PHP <source lang='PHP'> function harmonic() { $num_args = func_num_args (); $sum = 0; for ($i = 0; $i < $num_args; $i++) { $sum += 1 / f...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)


1 PHP

function harmonic() {
	$num_args = func_num_args ();
	$sum = 0;
	for ($i = 0; $i < $num_args; $i++) {
		$sum += 1 / func_get_arg ($i);
	}
	return $num_args / $sum;
}
echo harmonic(1, 2, 3, 4, 5);
// 2.1897810218978
echo harmonic(-1, 3, 4, 10293);
// -9.6022389365052
echo harmonic(-1, -2, -3, -4, -5);
// -2.1897810218978

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}