Cet algorithme effectue la récursivité sur une fonction factorielle.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication38 { class Program { public static int factorielle(int n) { if(n == 0) { return(1); } else { return (n * factorielle(n - 1)); } } static void Main(string[] args) { string n1; int n; Console.WriteLine("Ecrire n"); n1 = Console.ReadLine(); n = Convert.ToInt32(n1); n = factorielle(n); Console.WriteLine("le factorielle de n est : " +n); Console.ReadLine(); } } }
Thanks, great article.