C/Visual C - ayuda

 
Vista:

ayuda

Publicado por EDGAR (5 intervenciones) el 11/01/2009 05:22:15
HOLA

ESPERO QUE ME PUEDAN AYUDAR GRACIAS

ES UN PROGRAMA

ELABORAR UN PROGRAMA QUE APLIQUE UN METODO DE BUSQUEDA PARA ENCONTRAR UN NUMERO EN UN VECTOR ORDENEDO DE 10 ELEMENTOS.

PORFABOR ESTOY DECESPERADO
GARCIAS ESPERO RESPUESTA
BAY
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayuda

Publicado por jose (21 intervenciones) el 16/01/2009 00:22:27
#include< malloc.h >
#include< stdio.h >


/* _mlloc : malloc */
void _mlloc( void * buffer,
int size )
{
*(void**)buffer = malloc( size );
}


/* _buscar */
int _buscar( int * array, // vector.
int size, // tamaño del array.
int value ) // valor a buscar.
{

for( int i=0; i<size; i++ )
{
if( array[i] == value )
return i; // valor hallado.
}

return -1; // no se encontro valor.
}


/* main */
void main()
{

int search;
int result;
int * array; // vector.
int elements = 10; // cantidad de elementos.


// crear array utilizando malloc( esto es solo una forma dinamica ).
_mlloc( &array, elements * sizeof(int) );

// llenar array con valores.aleatorios.
array[0] = 1500;
array[1] = 3521;
array[2] = 3665;
array[3] = 1546;
array[4] = 78944;
array[5] = 15232;
array[6] = 4683014;
array[7] = 125;
array[8] = 78955;
array[9] = 1235444;


// buscamos un valor.
search = 0;
result = _buscar( array, elements, search );

// imprimimos resultado.
if( result >= 0 )
{
printf( "Valor encontrado en array[%i] = %i... ", result, search );
}
else
{
printf( "Valor no encontrado... " );
}


// liberamos memoria.
free( array );

}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar