answersLogoWhite

0


Best Answer

template<typename T> size_t min(const T a[], const size_t size)

{

// assume first element (index 0) has the smallest value

size_t selected=0;

// scan remainder of array looking for anything smaller than selected

for (size_t right=selected+1; right<size; ++right)

if (a[right]<a[selected])

selected=right;

return a[selected];

}

User Avatar

Wiki User

βˆ™ 9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 10y ago

You write it the same way you would in any other language. You store the value of the first element and then traverse the remainder of the array, one element at a time, comparing each element's value to the one you stored. If the current element's value is less than the stored value, then you update the stored value accordingly. When you've traversed the entire array, the stored value will contain the smallest value in the array.

In the following example, let us suppose that A is an array of n integers:

int small = A[0]; // store the first value in the array

for(int i=1;i<n;++i) // traverse the remainder of the array

if(A[i]<small) // compare the current element to the stored value

small=A[i]; // update the stored value

return(small); // return the smallest value

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C plus plus program that finds the minimum number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is potassium's minimum oxidation number?

Potassium's minimum oxidation number is zero.Its maximum is plus one.


C plus plus program to print number patterns?

bghjg


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


What is the contact number for family health plus insurance?

(1-877-934-7587) Family Health Plus (adult insurance program)


How to restart c plus plus program?

Exit the program and relaunch it.


What was the minimum number of electoral votes needed to win the presidential election of 2008?

270, that's half plus one.


How do you make a program that display odd number from one to twenty in c plus plus?

for (int i=1; i&lt;20; i+=2) printf ("%d\n", i);


Can you program games with c plus plus?

Yes, you can program games with C++.


Is there an answer book for the A plus program?

The A Plus Program is an initiative, not a test. So no, there is no answer book.


Minimum mark of 10 plus 2 for studying Bsc biotechnology?

Minimum mark for 10 plus 2 is 80%.


Write a c plus plus program that Reads 2 positive integers from a user it finds if the smaller in number of digits number is present in the larger number and its indices?

std::string a, b; std::cout &lt;&lt; "Enter two numbers: "; std::cin &gt;&gt; a &gt;&gt; b; size_t pos; if ((pos = a.find (b)) != a.npos) std::cout &lt;&lt; b &lt;&lt; " is part of " &lt;&lt; a &lt;&lt; " at index " &lt;&lt; pos; else if ((pos = b.find (a)) != b.npos) std::cout &lt;&lt; a &lt;&lt; " is part of " &lt;&lt; b &lt;&lt; " at index " &lt;&lt; pos;


How a program in c plus plus plus plus using function that returns the smallest of three floating-point numbers?

#include &lt;iostream&gt; using std::cin; using std::cout; using std::endl; double minimum(double arg1, double arg2, double arg3); int main() { cout &lt;&lt; "Enter first number: "; double firstNumber = 0.0; cin &gt;&gt; firstNumber; cout &gt;&gt; "Enter second number: "; double secondNumber = 0.0; cin &gt;&gt; secondNumber; cout &lt;&lt; "Enter third number: "; double thirdNumber = 0.0; cin &gt;&gt; thirdNumber; cout &lt;&lt; "\nThe smallest number is " &lt;&lt; minimum(firstNumber, secondNumber, thirdNumber) &lt;&lt; endl; return 0; } //All three arguments have to be different double minimum(double arg1, double arg2, double arg3) { double min = arg1; if (arg 1 &gt; arg2) { min = arg2; } else if (arg1 &gt; arg3) { min = arg3; } return min; }