In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use C language recursion in practice". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let's let the editor take you to learn how C language recursion is applied in practical problems.
Recursive knowledge point
The concept of recursion: the programming skill in which a program calls itself is called recursion. As an algorithm, recursion is widely used in programming languages. A process or function has a method of calling itself directly or indirectly in its definition or description, which usually transforms a large and complex problem into a smaller problem similar to the original problem. The recursive strategy requires only a small number of programs to describe the repeated calculations needed in the problem-solving process, which greatly reduces the amount of code of the program.
The popular understanding is that the function calls itself.
The main way of thinking about recursion is to reduce major events to small ones.
Two necessary conditions for Recursion
1. There is a restriction, and when this restriction is met, the recursion will not continue.
two。 It is getting closer and closer to this restriction after each recursive call.
(those who meet the above necessary conditions are not necessarily recursive, but those who do not meet the conditions are not necessarily recursive.)
First question of the title
Receive an integer value and print each bit in order
Input: 1234 output: 1234
Take a look inside the function:
# include void print (int n) {if (n > 9) {print (n / 10);} printf ("% d", n% 10);} int main () {int n = 0; scanf ("% d", & n); print (n); return 0;} second question
Find the factorial of n
Enter the inside of the function:
# include int factorial (int n) {if (n 0) return n * Pow (n, k-1); else if (k = = 0) return 1; else return 1.0 / Pow (n,-k);} int main () {int n = 0; int k = 0; scanf ("% d% d", & n, & k) Double ret = Pow (n, k); printf ("% lf\ n", ret); return 0;} question 7
Xiao Lele needs to take n steps in class.
So you can choose to take one step or two steps each time, so how many ways does he have?
Enter the inside of the function:
# include int jump (int n) {if (n)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.