Home > Back-end >  Define a double array, a total of 10 array elements, elements of value from the keyboard input. For
Define a double array, a total of 10 array elements, elements of value from the keyboard input. For

Time:10-11

Define a double array, a total of 10 array elements, elements of value from the keyboard input, and the most value in the array (the maximum and the minimum) and the value in the array subscript?

CodePudding user response:

 
#include
# define ARRSIZE 4
Int arr_max (double arr [], int n)
{
Double temp=0;
Int index=0, I=0;
Temp=arr [0].
For (I; i{
If (temp & lt; Arr [I])
{
Temp=arr [I];
index=i;
}
}
Return the index;
}

Int arr_min (double arr [], int n)
{
Double temp=0;
Int index=0, I=0;
Temp=arr [0].
For (I; i{
If (temp & gt; Arr [I])
{
Temp=arr [I];
index=i;
}
}
Return the index;
}

Int main ()
{
Double arr1={0} [ARRSIZE];
Int I, max_index min_index;
for (i=0; i{
Printf (" please enter the first % d array elements: \ n ", I + 1);
Lf the scanf (" % ", & amp; [I] arr1);
}
for (i=0; i{
Printf (" % 2 f \ t ", arr1 [I]);
}
printf("\n");
Max_index=arr_max (arr1, ARRSIZE);
Min_index=arr_min (arr1, ARRSIZE);
Printf (" the largest of the array subscript is: % d this element is: %, 2 f \ n ", max_index, arr1 [max_index]);
Printf (" minimum of the array subscript is: % d this element is: %, 2 f \ n ", min_index, arr1 [min_index]);
return 0;
}

CodePudding user response:

Thank you very much

CodePudding user response:

Int arr_min (double arr [], int n)
{
Int index=0, I=0;
for(i=1; iIf (arr [index] & gt; Arr [I])
index=i;
Return the index;
}
  • Related