After i key in 20 different value of float, what command should i use so that i can determine the largest and smallest value from these numbers ?
Chalson
0
Newbie Poster
Recommended Answers
Jump to PostMaybe use a array to store the variables , then sort the array in numerical order then access the first and last element of the array.
Jump to PostThe best way would be to calculate it during the process of input.
float s=0,l=0,x; for(int i=0;i<20;++i){ cin>>x; if(x>l) l=x; if(x<s) s=x; } /* Use the values */
Or after taking the input in an array, go through it and get the smallest and largest values.
Jump to PostMaybe use a array to store the variables , then sort the array in numerical order then access the first and last element of the array.
There are only 20 numbers. It's faster to linear search while saving the biggest and smallest as you go:
#include <iostream> …
Jump to Post@rpdm read my post again, it's the implementation of the same algo.
Did it occur to you that I was writing my post when you submitted yours and I didn't see it?
1. chalson wanted to get the numbers as input, so you won't require the time() and srand() and …
All 16 Replies
elsiekins
0
Junior Poster
techie1991
26
Junior Poster in Training
rpdm
4
Newbie Poster
techie1991
26
Junior Poster in Training
rpdm
commented:
All bad points. Thanks for assuming I'm an idiot.
+0
rpdm
4
Newbie Poster
techie1991
26
Junior Poster in Training
rpdm
4
Newbie Poster
techie1991
commented:
c'mon, you are not here to fight.! are you? see my previous posts and you will come to know how idotic it is to get offensive here.!
+0
techie1991
26
Junior Poster in Training
Ketsuekiame
860
Master Poster
Featured Poster
rpdm
4
Newbie Poster
elsiekins
commented:
Rude and obnoxious
+0
Ketsuekiame
860
Master Poster
Featured Poster
rpdm
4
Newbie Poster
Ketsuekiame
860
Master Poster
Featured Poster
elsiekins
0
Junior Poster
rpdm
commented:
Why defend a slower *and* more complex solution?
+0
elsiekins
0
Junior Poster
PsychoLogic
1
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.