/*
* PR1TON -- use indirect recursion to print the integers
* from A to B
*
* Matt Bishop, ECS 36A
*
* April 30, 2024
* -- original program written
*/
#include <stdio.h>
/*
* macros
*/
#define A 1
#define B 6
/*
* prototypes
*/
void fun2(int, int);
/*
* first function: print, increment, call second function
*/
void fun1(int n, int N)
{
/* if n (current int) is over the top N, skip what follows */
if (n <= N){
printf("%d ", n); /* print integer */
n++; /* go to next integer */
fun2(n, N); /* call second function */
}
}
/*
* second function: print, increment, call first function
*/
void fun2(int n, int N)
{
if (n <= N){
printf("%d ", n); /* print integer */
n++; /* go to next integer */
fun1(n, N); /* call second function */
}
}
/*
* main function
*/
int main(void)
{
/* print away! */
fun1(A, B);
putchar('\n');
/* phew -- glad that's over */
return(0);
}
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |