Problems C: recursion using the n-th digit (c #)

Title Description

A number of rules, are as follows: 1,1,2,3,5,8,13,21,34 ....... N is the number of digits required?

Entry

Enter a positive integer representing seeking first digits

Export

N bit digital outputs

Sample input

30

Sample Output

832040

prompt

Enter the number must be greater than zero

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(calc(n));
            Console.ReadKey();
        }

        static int calc(int n)
        {
            if (n < 0) return 0;
            else if (n == 1)
            {
                return 1;
            }
            else
            {
                return calc (n - 1) + calc (n - 2); 
            } 
        } 
    } 

}

  

Guess you like

Origin www.cnblogs.com/mjn1/p/12402700.html