Home > Back-end > [for] C language function is used to implement for a maximum of one dimensional array, requirements
[for] C language function is used to implement for a maximum of one dimensional array, requirements
Time:09-17
Bald, I don't think for a long time to come out, can not find people for help, help, send a post o, I write nothing, operation is to size for maximum is meng hope warrior comments help
CodePudding user response:
_array int calc_max_val (int * and an int _array_len) { Int Max=0; If (_array==NULL | | _array_len==0) return 0; For (int I=0; I & lt; _array_len; I++) { If (Max & lt;=_array [I]) Max=_array [I]; }
return max; }
Int main (void) { //int array []={1,2,0,5,6,77,88,99, 1}; An int array []={1, 2, 0, 5, 6, 77, 88, 99589848}; Int Max=calc_max_val (array, sizeof (array)/sizeof (array [0])); Printf (" array "s Max value % d \ r \ n", Max); system("pause"); return 0; }
CodePudding user response:
For maximum a for loop is enough
Int calculate (int x [5]) { Int Max=0; for(int i=0; I<5; I++) { If (Max & lt; A [I]) { Max=a, [I]. } } return max; }