Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Finding minimum with a recursive function

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
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You should compile with warnings switched on. rekursiv does not always return a value.

Change

rekursiv( v, i + 1, n, min );

to

return rekursiv( v, i + 1, n, min );
over 4 years ago · Santiago Trujillo Denunciar

0

In function (int rekursiv( int v[], int i, int n, int *min ) ), must be return integer so your last condition does not return anything. You should check last condition ELSE

else {
         if( *min < v[ i ] ){
             *min = v[ i ];

             }//end if
         rekursiv( v, i + 1, n, min );

         }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda