Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @Author: juliarnasution
- * @Date: 2020-04-03 10:07:14
- * @Last Modified by: Dell
- * @Last Modified time: 2020-04-03 10:26:27
- */
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Rekursif extends CI_Controller {
- public function index()
- {
- $this->contoh_rekursif(1);
- echo "<br/>";
- $n = 5;
- echo "nilai faktorial ".$n." adalah ";
- echo $this->faktorial($n);
- }
- public function contoh_rekursif($param)
- {
- if ($param>10) {
- return false;
- }
- echo "sekarang urutan ke ".$param;
- echo "<br/>";
- return $this->contoh_rekursif($param+1);
- }
- public function faktorial($n)
- {
- if ($n>2) {
- echo $n." * ";
- return $n * $this->faktorial($n-1);
- }else{
- echo $n." * ".($n-1). "= ";
- return $n;
- }
- }
- }
- /* End of file Rekursif.php */
- /* Location: ./application/controllers/Rekursif.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement