Entradas

Mostrando entradas de enero, 2020

get MAX and MIN with pointers from an array in c

This example will help you if you already have the array A function will receive the array by using pointers If not you only have to make a cycle and ask for numbers and scan them on the main #include < stdio.h > void prnt( int *); main() { int array []={ 3 , 4 , 6 , 1 , 2 , 7 , 8 , 10 , 12 , 5 }; prnt( array ); } void prnt( int * array ){ int i, c ; int *minimum, *m; minimum = array ; m= minimum; for ( c = 1 ; c < 10 ; c++ ) { if ( *( array +c) < *minimum ) { minimum = ( array +c); } } for ( c = 1 ; c < 10 ; c++ ){ if ( *( array +c) > *m ) { m = ( array +c); } } printf( "Max %d.\n" , *m); printf( "Min %d.\n" , *minimum); }