[ create a new paste ] login | about

Link: http://codepad.org/p5IVhzJE    [ raw code | output | fork ]

nel - C, pasted on Jan 30:
#include <stdlib.h>
#include <stdio.h>


int recursiveMinimum(int my_array[],unsigned array_size);

int main()
{
	int my_array[10]={-11,2,3,-5,3,-94,-7,-1,10,-80};
	printf("Current Minimum is : %d\n",recursiveMinimum(my_array,10));
	return (0);
}

int recursiveMinimum(int my_array[],unsigned array_size)
{
	int current_minimum;
	/*Stop condition for the recursion*/
	if (array_size == 1)
	{
		/*Don't forget that there is still one value we didn't check ...*/
		return (my_array[array_size - 1]);
	}
	else
	{
		/*Call the function recursively to get the minimum in the current sub-array
		Note that the current sub array "doesn't contain" the value stored in the top 
		of the array*/
		current_minimum = recursiveMinimum(my_array,array_size - 1);
                printf("\n* %d \n", current_minimum);
		/*Compare the current_minimum with the value in the top of the array*/
		if (current_minimum > my_array[array_size - 1])
		{
			current_minimum = my_array[array_size - 1]; 
		}
		/*Return the current recursion result*/
		return (current_minimum);
	}
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

* -11 

* -11 

* -11 

* -11 

* -11 

* -94 

* -94 

* -94 

* -94 
Current Minimum is : -94


Create a new paste based on this one


Comments: