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;
}

CodePudding user response:

reference 1st floor xws245925587 response:
int calc_max_val (int * _array, 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;
}


The buggy code, is considered as the elements in the one-dimensional array is negative, the maximum value is 0? Also conform to the requirements of the program?

CodePudding user response:

refer to the second floor WhiteCCai 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;
}


The buggy code, is considered as the elements in the one-dimensional array is negative, the maximum value is 0? Also conform to the requirements of the program?

CodePudding user response:

[]
 int calculate (int x, int len) 
{
Int Max=a, [0].
for(int i=1; I{
If (Max & lt; A [I])
{
Max=a, [I].
}
}
return max;
}

For your reference ~

CodePudding user response:

reference 3 building self-confidence boy reply:
Quote: refer to 1st floor xws245925587 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;
}


The buggy code, is considered as the elements in the one-dimensional array is negative, the maximum value is 0? Also conform to the requirements of the program?


Yes, there is a bug, in Max value is one of the elements of the array

CodePudding user response:

Can you help to check out the problem, I wrote, according to what you said is the output is not accurate

CodePudding user response:

The
reference 5 building self-confidence boy reply:
 int calculate (int x [], int len) 
{
Int Max=a, [0].
for(int i=1; I{
If (Max & lt; A [I])
{
Max=a, [I].
}
}
return max;
}

For reference ~

# include
Int calculate (int x [], int len)
{
Int Max=x [0];
For (int n=1; N{
If (Max & lt; X [n])
{
Max=x [n].
}
}
return max;
}
Int main ()
{
Float a [5], Max; int i;
Printf (" please enter the number 5: \ n ");
The scanf (" % d ", & amp; i);
Max=calculate (a, I);
Printf (" % f ", Max);
return 0;
}
  • Related