1. ## recursive problem

please i want to write this program nonrecursivly and i don't know how
can you help me?

void f(int[], int, int);
int main()
{ int a[]={2, 4, 6};
f(a, 0 , 2);
return 0; }

void f(int array[], int low, int high)
{ printf("%d ", array[low]);
if(low == high)
return;
else f(array, low + 1, high );
}

i know the output will be 2 4 6

2. First of all why?

Anwser:

Maybe use a while loop

3. why?

i want to know how
because i've got amidterm tomorrow

i will see how to use it with while
but should i change what is given to the function or i keep them like they are i ment a, 0 and 2

and what about the if else statment should i cancel it
and put this insted

printf("%d", array[low]);
while(low!=high){
for(int i=0; i<=2;i++){
low++;
printf("%d", array[low]);}
}

4. ## Re: recursive problem

Originally posted by kuwait
please i want to write this program nonrecursivly and i don't know how
can you help me?

void f(int[], int, int);
int main()
{ int a[]={2, 4, 6};
f(a, 0 , 2);
return 0; }

void f(int array[], int low, int high)
{ printf("%d ", array[low]);
if(low == high)
return;
else f(array, low + 1, high );
}

i know the output will be 2 4 6
You said if low == high return so if you put it in a while loop k\like you did it will never end if low==high!
so keep the if statement and combine it with your second thing to make a comprimise

useing the for statemt will clean your code and make it easier to understand so use it

5. thanx i've got a way to do it

while(low!=high+1)

6. Sounds good. If you need any toher help feel free to ask