Calling recursive function twice consecutively
Posted
by
Zack
on Stack Overflow
See other posts from Stack Overflow
or by Zack
Published on 2012-11-03T18:01:18Z
Indexed on
2012/11/04
5:01 UTC
Read the original article
Hit count: 139
Filed under:
c
#include <stdio.h>
#define LENGTH 16
void makeBranches(int, int);
void display(int, int);
int main(){
makeBranches(0, LENGTH-1);
}
void makeBranches(int left, int right){
if(left >= right){
return;
} else{
display(left, right);
makeBranches(left, (right+left)/2);
makeBranches((right+left/2)+1, right);
}
}
void display(int left, int right){
printf("%d, %d", left, right);
int mid = (left+right)/2;
int i;
for(i = left; i <= right; i++){
if(i == mid)
printf("X");
else
printf("-");
}
if(right == LENGTH-1)
printf("\n");
}
The problem that I am having is the second call of makeBranches only executes with the values that caused the first call of makeBranches to return and not the original values that the first call used.
© Stack Overflow or respective owner