Friday 26 July 2013

Recursive in C#

A Method can call another methods but it can also call itself. When a mathod calls itself is called Recursive . 

using
System.Collections.Generic;using System.Linq;using System.Text;using System;namespace InterfaceApplication{

class Program{static void Main(){

Program a = new Program();
Console.WriteLine(a.Fib(10));
Console.Read();
}

public long Fib(int n){

if (n == 0 || n == 1)return n;
return n * Fib(n - 1);}
 
 
}
}

No comments:

Post a Comment