Your best bet would probably be to iterate through the array using a for loop and compare each value to the current low and high values (which you would store in a local variable)
for example:
for each element in array
{
if current is less than lowest_value
lowest_value = current
else if current is greater than highest_value
highest_value = current
}
#include <stdio.h>
int main()
{
int array[100], smallest, size, c, location = 1;
printf("Enter the number of elements\n");
scanf("%d",&size);
printf("Enter %d integers\n", size);
for ( c = 0 ; c < size ; c++ )
scanf("%d", &array[c]);
smallest = array[0];
for ( c = 1 ; c < size ; c++ )
{
if ( array[c] < smallest )
{
smallest = array[c];
location = c+1;
}
}
printf("Smallest element is present at location %d and it's value is %d.\n", location, smallest);
getch();
return 0;
}
I look for the array element that contains the smallest value.
1010
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
The simplest way is usually to iterate through an array using a loop and store either the index or the value of the highest number you find. For example: int findLargestIndex(int *array, int arraysize) { int largestIndex = 0; for(int i = 0; i < arraysize; i++) { if(array[i] > array[largestIndex]) largestIndex = i; } return largestIndex; }
Basically, &array[i]; That is, the memory location for an array object with index i. Or, you can do: (array + i);
** pseudo code ** if array length == 1, return first element else if array length > 1 max = first element for second item to last item if item > max max = item return max else // array length is 0 error
Find the minimum and maximum of what? An array?
java is very most important language in computer field. .net is also useful
algebra
1010
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
write an assembly language program to find sum of N numbers
In Calculus, to find the maximum and minimum value, you first take the derivative of the function then find the zeroes or the roots of it. Once you have the roots, you can just simply plug in the x value to the original function where y is the maximum or minimum value. To know if its a maximum or minimum value, simply do your number line to check. the x and y are now your max/min points/ coordinates.
Traverse the array from index 0 until you find the number. Return the index of that number.
Range = Maximum value - Minimum value
You can get many example of"c programming" Reference:cprogramming-bd.com/c_page1.aspx# integer grades
Assuming the matrix is two-dimensional, a single row would just be an ordinary array. To find the minimum element of an array, store the first element, then traverse the remainder of the array. If we find a value smaller than the stored value, replace the stored value. Once we have traversed the whole array, the stored value is the smallest value. We then traverse the array once more, subtracting that value from each element. The following C code shows how we might implement this for a matrix of doubles: #include<stdio.h> double array_min (double array[], size_t n) { double min= array[0]; for (size_t i=1; i<n; ++i) if (array[i]<min) min=array[i]; return min; } void subtract (double array[], size_t n, double value) { for (size_t i=0; i<n; ++i) array[i] -= value; } void print_matrix (double * array[], size_t rows, size_t cols) { printf ("{"); for (size_t row=0; row<rows; ++row) { printf ("{"); for (size_t col=0; col<cols; ++col) printf ("%d, ", array[row][col]); printf ("\b\b}, "); } printf ("\b\b} \n"); } int main () { const size_t rows = 4; const size_t cols = 5; double matrix[rows][cols] = {{0.1, 0.2, 0.3, 0.4, 0.5}, {1.0, 0.9, 0.8, 0.7, 0.6}, {1.4, 1.5, 1.3, 1.1, 1.2}, {1.8, 1.7, 1.6, 2.0, 1.9}}; print_matrix (matrix, rows, cols); for (size_t row=0; row<rows; ++row) { double min = array_min (matrix[row], cols); subtract (matrix[row], cols, min); } print_matrix (matrix, rows, cols); return 0; } Example output: {{0.1, 0.2, 0.3, 0.4, 0.5}, {1.0, 0.9, 0.8, 0.7, 0.6}, {1.4, 1.5, 1.3, 1.1, 1.2}, {1.8, 1.7, 1.6, 2.0, 1.9}} {{0.0, 0.1, 0.2, 0.3, 0.4}, {0.4, 0.3, 0.2, 0.1, 0.0}, {0.3, 0.4, 0.2, 0.0, 0.1}, {0.2, 0.1, 0.0, 0.4, 0.3}}
Assuming the standard x and y axes, the range is the maximum value of y minus minimum value of y; and the domain is the maximum value of x minus minimum value of x.