Advertisement
rasyid03

soalno4

Jul 2nd, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace WebApplication1
  9. {
  10.     public partial class WebForm4 : System.Web.UI.Page
  11.     {
  12.         protected void Page_Load(object sender, EventArgs e)
  13.         {
  14.             // Faris Rasyid | 50421483
  15.             SetFibonacci(4);
  16.             SetFibonacci(10);
  17.             SetFibonacci(7);
  18.         }
  19.  
  20.         public int Fibonacci(int x)
  21.         {
  22.             if (x <= 0)
  23.             {
  24.                 return 0;
  25.             }
  26.             else if (x == 1)
  27.             {
  28.                 return 1;
  29.             }
  30.  
  31.             return Fibonacci(x - 1) + Fibonacci(x - 2);
  32.         }
  33.  
  34.         public void SetFibonacci(int PanjangDeret)
  35.         {
  36.             for (int i = 0; i < PanjangDeret; i++)
  37.             {
  38.                 if (i == PanjangDeret - 1)
  39.                 {
  40.                     Response.Write(Fibonacci(i) + "<br/>");
  41.                 }
  42.                 else
  43.                 {
  44.                     Response.Write(Fibonacci(i) + ",");
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement