-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d66f9a
commit b454718
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"files.associations": { | ||
"ostream": "cpp", | ||
"iostream": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Basic Concept/7 Recursion/2 Types of Recursion/treeRecursion.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> // Include the standard input-output stream library | ||
using namespace std; // Use the standard namespace | ||
|
||
// Function definition for 'fun' which performs tree recursion | ||
void fun(int n) | ||
{ | ||
if (n > 0) // Base case: when n is greater than 0 | ||
{ | ||
cout << n; // Print the current value of n | ||
fun(n - 1); // Recursive call to 'fun' with n-1 | ||
fun(n - 1); // Another recursive call to 'fun' with n-1 | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n = 3; // Initialize n with a value of 3 | ||
fun(n); // Call the 'fun' function with n | ||
cout << "\nThis is an example of Tree Recursion" << endl; // Print a message | ||
cout << "Output:" << endl; // Print a label for the output | ||
return 0; // End of the main function | ||
} | ||
|
||
// Output: 3211211 |