diff --git a/print1toN/using_indirect_recursion.c b/print1toN/using_indirect_recursion.c new file mode 100644 index 00000000..36586ad5 --- /dev/null +++ b/print1toN/using_indirect_recursion.c @@ -0,0 +1,41 @@ + +// C program to print from 1 to N using +// indirect recursion/ +#include + +// 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; +}