Whatever the input, the result is always 0. Why is that ?
#include <stdio.h>
#include <conio.h>
int rekursiv( int v[], int i, int n, int *min );
int main( void )
{
int v[ 100 ];
int n, i, min;
printf( "Shkruanni n: " );
scanf( "%d", &n );
printf( "Shkruani elementet e vektorit.\n" );
for( i = 0; i < n; i++ ){
scanf( "%d", &v[ i ] );
}//end for
min = v[ 0 ];
i = 1;
printf( "Minimumi eshte %d.", rekursiv( v, i, n, &min ) );
getche();
return 0;
}//end main
int rekursiv( int v[], int i, int n, int *min )
{
if( i == n - 1 ) {
return *min;
}//end if
else {
if( *min < v[ i ] ) {
*min = v[ i ];
}//end if
rekursiv( v, i + 1, n, min );
}//end else
}//end rekursiv
You should compile with warnings switched on.
rekursiv
does not always return a value.Change
to