hello guys...i've question to ask...

there are 5 numbers given.. 10,8,3,6,15

how to do the coding to determine which one is the smallest and biggest number..thanks..

there are 5 numbers given.. 10,8,3,6,15

how to do the coding to determine which one is the smallest and biggest number..thanks..

can u give me a rough idea how to do it?..because i'm still a beginner...never use vector before..

It was a joke. Finding the largest and smallest numbers from a given set is pretty easy.

You need two variables, one for the largest number(Initialize very small) and one for the smallest (Initialize very large).

Then read in your numbers one after the other, and if they are smaller than/larger than the respective variables simply assign the variable the value of that number.

You need two variables, one for the largest number(Initialize very small) and one for the smallest (Initialize very large).

Then read in your numbers one after the other, and if they are smaller than/larger than the respective variables simply assign the variable the value of that number.

sorry my mistake...what i meant here is how to do the coding using the vector..and i have 5 inputs to compare..i don't really know how to use vector..if you mind to show me an example?

Google C++ vector example will take you to the reference section on this site.

**Google is your best friend**

BlackSheep wrote:

You could initialise them both to zero, no need to initialise them to small / large values.

HTH

BlackSheep wrote:

You need two variables, one for the largest number(Initialize very small) and one for the smallest (Initialize very large). |

You could initialise them both to zero, no need to initialise them to small / large values.

HTH

You could initialise them both to zero, no need to initialise them to small / large values. |

In this case a less than check (for smallest number) would always favour the zero. And if negative numbers are involved then the largest number might be compromised as well.

I guess the best route would be to initialize both to the first value read.

I guess the best route would be to initialize both to the first value read. |

Yes, that is what I meant.

Topic archived. No new replies allowed.