#include <iostream>
using namespace std;
/**
* Returns the difference between the largest and smallest element
of the array
* This function takes array and length of array in input
*/
int range(int *array, int length) {
int i;
int smallest = INT_MAX;
int largest = INT_MIN;
for(i = 0; i < length; i++) {
if(array[i] < smallest) {
smallest =
array[i];
}
if(array[i] > largest) {
largest =
array[i];
}
}
return largest - smallest;
}
int main() {
int array[8] = {-9, 10, 20, -30, 70, 18, -25,
40};
cout << range(array, 8) << endl;
return 0;
}
Screenshots --
Code
Output
c++ 2. Write a CH function called range that returns the difference between the largest and...
This program should be in C. It should have adequate comments. Write a function called difference () that returns the difference between the largest and smallest elements of an array-of-long. Use only pointers to iterate the array. Test the function in a simple program.
#Python 1.Write a function called difference() that accepts a list of numbers from the user and returns the difference between the largest and the smallest numbers in the list as follows: >>> difference() Please enter a list: [100, 102, 106, -10] 116 >>> difference() Please enter a list: [1,2,3,4,5,6,7,8,9,10] 9 >>>
Write a C function called min which takes 2 integers as input, and returns the smallest as the result?
C++ ( Please Read) Write a function prototype and a function definition called getTotal that receives an array of type double, the number of rows in the array. It returns the total of all elements in the array.
Write a function that returns the index of the smallest element in an array of integers. If there are more such elements than one, return the smallest index. C programming
The range of a set of measurements is the difference between the largest and the smallest values. The empirical rule suggests that the standard deviation of a set of measurements may be roughly approximated by one-fourth of the range that is, -**, G range The acidity of soils is measured by a quantity called the pH, which may range from 0 (high acidity) to 14 (high alkalinity). A soil scientist wants to estimate the average pH for a large field...
Using C++ And #include <stdio.h> #include <stdlib.h> #include <time.h> a) Write a main function and declare an array with 100 elements. b) In the main, initialize each number in the array to be a random number between 100 and 200. c) Write a function that returns the value of the smallest number in the array. Call this function from the main and print the result. d) Declare a 2D array with dimensions 2x2 and initilize the array, as follows: [1,...
Write a function called ''minandmax'' . Function ''minandmax'' takes only one input argument that is a matrix M . This matrix M can be any size (any number of columns and rows) with any random integer values . Function ''minandmax'' returns two output arguments. The first output argument is called ''difference_row'' that returns a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. The second output argument is called ''difference_all''...
JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...
MatLab Help!! Write a function called Difference to calculate the central difference, forward diflerence, and backward diference approximation to an function within a given range of xmin:xinc:xmax The input argument of the function Difference is the handle to an anonymous function, a row array xmin:xinc:xmax The differences should be returned as a row array, calculated at xmin xinc xmax Restriction. The function should not use loops Ex func - (x) x.3 xmin-3 xinc-e.25; xmax-4; [backDifference, centralDifference, forwardDifference] Derivative(func, xmin, xmax,...