answersLogoWhite

0

You simply walk through the array and whenever you find a smaller element you remember its value and location.

E.g. If you have an array of integers called pArray that contains 100 elements, here's what the code might look like:

int cPos 0, int nMin pArray[0]; // Provisionally assume the first element is smallest.

for ( int n 1; n < 100; ++n )

{

if ( pArray[n] < nMin )

{

// We've found a new smaller element, record its position and value.

nMin pArray[n];

cPos n;

}

}

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

The minimum number of comparisons requied to find the second smallest element in a 1000 element array is?

1010


How do arrays differ from single memory position variables?

A single memory position variable can store only one value of its type. An array can store n number of values, where n is the size of the array.


How do you find the minimum value of an array in c language?

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 }


What is the function of break in java programming?

The break keyword is used to prematurely exit the current block of code. Java only allows it to be used in the body of a loop or switch, and is helpful when you want a special reason to stop executing that code.Here is an example, in which we will search through an array of integers for a particular value. If that value is found, we will print out its location in the array and then stop running.void search(int num, int[] array) {// Store the position of num in array (or -1 if it wasn't found)int position = -1;// Here is our search loopfor(int i = 0; i < array.length; ++i) {if(array[i] == num) {// If we find the number, store its position and exit the loopposition = i;break;}}// Print out our resultsif(position >= 0) {System.out.println(num + " found at position: " + position);}else {System.out.println(num + " was not found in the array");}}


What is The number of elements in an array is called?

the length of the array

Related Questions

What is the process for finding the kth smallest number in an unsorted array?

To find the kth smallest number in an unsorted array, you can use a sorting algorithm like quicksort or heapsort to arrange the array in ascending order. Then, you can simply access the kth element in the sorted array to find the kth smallest number. This process ensures that the kth smallest number is easily identified and retrieved from the array.


How can you get position of number from given some number by using array in c language?

Traverse the array from index 0 until you find the number. Return the index of that number.


What is the value of the kth smallest element in the given array?

The value of the kth smallest element in the array is the kth element when the array is sorted in ascending order.


The minimum number of comparisons requied to find the second smallest element in a 1000 element array is?

1010


How do arrays differ from single memory position variables?

A single memory position variable can store only one value of its type. An array can store n number of values, where n is the size of the array.


What is the minimum absolute difference between any two elements in a given array?

The minimum absolute difference between any two elements in a given array is the smallest positive number that can be obtained by subtracting one element from another in the array.


How do you find the minimum value of an array in c language?

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 }


What are array of string pointers?

An array of pointers to string would contain, per array position, a number dictating which memory address holds the string data. For example, position [0] in an array would contain a memory address. This memory address can be de-referenced to obtain the actual information held within that memory address.


What is squre array?

A square array is an array in which the number of rows is the same as the number of columns.


Is an array that is in sorted order a min heap?

Yes, an array that is in sorted order is considered a min-heap because the smallest item in the array is the root. Also, the rest of the items in the array will gradually get bigger from the root until the end of the array.


What is the minimum number of swaps required to sort an array?

The minimum number of swaps required to sort an array is equal to the number of inversions in the array.


How do you find particular element in array?

by using index position we can find the particular element in array.