/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: the rule for the number of columns is as follows: 30th, 34? (Implemented using recursive algorithms)
* Author: Lei hengxin
* Completion date: January 1, September 09, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
[Csharp]
<Span style = "font-size: 24px;"> using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("this is a" Number of Columns with the following rules: 30th, 34... What is the-digit number ?" Program ");
Console. Write ("which number of digits do you want to calculate? ");
Int number = int. Parse (Console. ReadLine ());
Int m = f (number); // Recursive Function
Console. WriteLine ("{0} digits: {1}", number, m );
Console. ReadKey ();
}
Static int f (int number) // recursion is to call itself in a process or function.
{
Int fact;
If (number = 0 | number = 1) // when using a recursive policy, there must be a clear recursive termination condition, called the recursive exit.
{
If (number = 0) // This occurs when number is equal to 2.
{
Fact = 0;
}
Else
{
Fact = 1;
}
}
Else
{
Fact = f (number-1) + f (number-2 );
}
Return fact;
}
}
}
</Span>
Running result:
Experience Accumulation:
1.
Recursion is an important method in computer science.
Algorithms that can use recursive descriptions usually have the following features: To solve the N-scale problem, we try to break it down into smaller-scale problems, then, we can easily construct solutions to big problems from the solutions to these small problems, and these smaller problems can also be decomposed into smaller problems using the same decomposition and synthesis methods, then, we can deconstruct these smaller problems to solve large-scale problems. In particular, when the scale N is 1, it can be directly solved.