-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #540 from Rimjhim28/patch_1
Print 1 to N using indirect recursion using Java
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 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,41 @@ | ||
|
||
// C program to print from 1 to N using | ||
// indirect recursion/ | ||
#include<stdio.h> | ||
|
||
// We can avoid use of these using references | ||
#define N 20; | ||
int n = 1; | ||
|
||
// Prints n, increments n and calls fun1() | ||
void fun1() | ||
{ | ||
if (n <= N) | ||
{ | ||
printf("%d", n); | ||
n++; | ||
fun2(); | ||
} | ||
else | ||
return; | ||
} | ||
|
||
// Prints n, increments n and calls fun2() | ||
void fun2() | ||
{ | ||
if (n <= N) | ||
{ | ||
printf("%d", n); | ||
n++; | ||
fun1(); | ||
} | ||
else | ||
return; | ||
} | ||
|
||
// Driver Program | ||
int main(void) | ||
{ | ||
fun1(); | ||
return 0; | ||
} |