Solução: Problema da seqüência de Fibonacci (Fábio Novais)

From AdonaiMedrado.Pro.Br
Revision as of 23:45, 7 April 2009 by 200.17.147.2 (Talk) (New page: <code lang="csharp"> using System; public class SequenciaFibonacci { public static int GerarSequencia(int n) { if(n == 0 || n == 1) return n; else return GerarSequenci...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
using System;
 
	public class SequenciaFibonacci
	{
		public static int GerarSequencia(int n)
		{
			if(n == 0 || n == 1)
				return n;
			else
				return GerarSequencia(n - 1) + GerarSequencia(n - 2);	
		}
	}
 
	public class Principal
	{
		public static void Main(string[] args)
		{
			int n = Convert.ToInt32(Console.ReadLine());
 
			if((n <= 40) && (n >= 0))
			{
				for(int i = 0; i < n; i++)
					Console.WriteLine(SequenciaFibonacci.GerarSequencia(i));
			}
			else
				Console.WriteLine("Numero invalido!");
		}
	}