answersLogoWhite

0


Best Answer

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

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

A Discussion has been started about this question. To view it and take part, please click on the middle button shown below.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Find the smallest number and its position using array with c coding?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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");}}


How do you calculate array of 10 number using array in c?

#inculde&lt;iostream&gt; using namespace std; int smallestIndex(int[],int) //function prototype void main() { int arr[10]={2,5,6,9,3,7,1,15,12,10}; int position; position=smallestIndex(arr,10); cout&lt;&lt;"the smallestIndex

Related questions

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.


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 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.


How do you find particular element in array?

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


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


How do you calculate array of 10 number using array in c?

#inculde&lt;iostream&gt; using namespace std; int smallestIndex(int[],int) //function prototype void main() { int arr[10]={2,5,6,9,3,7,1,15,12,10}; int position; position=smallestIndex(arr,10); cout&lt;&lt;"the smallestIndex


How delete an array of object within the object in C?

First locate the position of an array by search after than use a delete function to delete an array