• C

# Comparing !

Hello,

I was wondering If you would care to help me on this! I have a program that has array[], like x[k], and this gives different values of x but i want to compare the xs how can I do that !
exple :
for (k=0;k<10;k++){
x[k]= function(a[k], b[k]);
printf("x=%f\n", x[k]);
}

and I want to compare all xs and get the bigger value ! How can I do that ! pleasssse
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DBACommented:

Hi Besbous,

If you're just looking for the largest value, loop through the entire array and "save" the biggest one.

int Largest;
int Array[SomeSize];
int index;

Largest = Array[0];
for (index = 1; index < SomeSize; index++)
if (Array[index] > Largest)
Largest = Array[index];

That's all that there is to it!

Good Luck,
Kent
Commented:
Kent,
i didnt expect this from you.  this is outright homework problem
Author Commented:

hi Kdo,
in my program I wanna get the the bigget value of all r1[k], of all g1[k] and of all b1[k], coz each r1[k].. is related to g_y[k] and g_x[k],
so if i can get the largest of all r1[k] is it possible to get the g_x[k] and g_y[k] associeted to ?

for(k=0;k<10;k++){
r1[k]=rgb(img_src,g_y[k],g_x[k],R);
g1[k]=rgb(img_src,g_y[k],g_x[k],G);
b1[k]=rgb(img_src,g_y[k],g_x[k],B);
printf("R=%d, G=%d, B=%d\n", r1[k], g1[k], b1[k]);

DBACommented:
Hi akshayxx,

I read it as homework too, and thought about how to best answer it.  Based on not knowing of any C course where a complete programming assignment is anything this trivial, I offered up the solution.  Looking back, I went too far and should have just left instructions.  I apologize to you and the rest of the membership.

We now have a follow-up to the original question and it appears that this may not be homework, but I still went too far.

Hi Besbous,

Getting the largest value from a list is trivial, as I've shown you.  Before I offer any more solutions I'd like an assurance that this is not homework.  The rules of the board expressly forbid the experts from doing other people's homework.

How is it that you're deep enough into programming to be evaluating pixel values, but can't write a simple maximum() function?

Kent

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Kent,
How can you detect a question and post a reply all in two minutes!!!

Akshay,
this is not homework and if it is, it a small part of a big project

Besbous,
>so if i can get the largest of all r1[k] is it possible to get the g_x[k] and g_y[k] associeted to ?
If there is some correspondence between the values, then the index i at which you found biggest r1[], the same index will have biggest values in g_x[] and g_y[]

otherwise, you can run the same loop as r1[] for g_x[] and g_y[] to get the largest value ... all you need to do is replace r1[] by g_x[] or g_y[] as required
Author Commented:
Thx a lot sunny!

actually I don t need the biggest values in g_x[k] and g_y[k], I need the g_x[k] and g_y[k]  related to the biggest r1[k]! but actually I tried but couldn t get the biggest value of r1[k]! so im kinda confused ! :(!
DBACommented:
Hi Besbous,

This is just as easy.  When you find an r1[] that is larger than the previous, save it and the g_x[] and g[] values.

if (r1[k] > LargestR1)
{
LargestR1 = r1[k];
LargestGX = g_x[k];
LargestGY = g_y[k];
}

Still waiting for an answer to my previous question,
Kent
Author Commented:
Oh ! well the thing is ! this is not a homework ! it s a project ! the thing is what you suggested I already tried something similar, maybe I didn t express my self clearly ! but to get the largest value the way u wrote, it is quite simple, but the thing is I had problem using the g_x[k] and g_y[k] out of the biggest value of all r1[k], g1[k] and b1[k].

anyway probably I shouldn t have asked that !
thx for your help guys !
DBACommented:
Hi Besbous,

Don't be bashful about asking questions!  That's what the board is for and there are quite a few of us willing to help.  The three people that have responded here are three of the most prolific responders in the C thread.  (Actually, Sunny's in his own league as far as number of answers is concerned -- the rest of kind of pick up the scraps.)

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20690354.html

Anyway, glad that we could help
Kent
Author Commented:

Yeah I totally understand ! and of course you re right ! and you guys are really great with ur answers ! just sometimes after 9 hours of sitting facing the computer and trying to make a Robot distinguish colors... is tiring, so it doesnt help to see some simple stuff! Oh well!! :)
You guys are great ! Thx a lot ! Hope I can help too some other time !
Author Commented:
OK I solved the problem! have a good day/night guys !
Commented:
sorry kent, was too fast to come to conclusion, but he must better have specified the source of the problem.. otherwise in first go it does look like a  homework :-)

for Besbous... if u were satisfied with the solution, wouldnt it have been nicer to award with A grade...
akshay
Commented:
>(Actually, Sunny's in his own league as far as number of answers is concerned -- the rest of kind of pick up the scraps.)
LOL Kent, how did you imagine that ... you are more than 3000 points ahead of me for the month of december<gasp>... you have got a weird imagination or are you being too humble ? ;o)

and I admire your memory ... where did you dig out that question from ?
DBACommented:

Hi Sunny,

December is a bit of an anomaly.  Since most schools in the western hemisphere give their students quite a bit of time off (1 to 3 weeks) there are a lot fewer questions from students.  I don't know what schedule students keep in your time zone, but there seems to be a lot fewer questions posted during your "prime time".  I'm sure that things will normalize the first week of January.

That thread has bothered me ever since I got involved in it.  Then to have the snivelling wimp develop a "I did it and you can't do anything about it" attitude really torched me.  I'd had an offline discussion with one of the mods about it and offerred to use my university contacts to contact the poster's administration, but (much to the mod's credit) the request was declined since it went againt EE's rules.  OTOH, by now the poster is reaping his own rewards and trying to figure out how and engineering degree barely qualifies him to ask, "eat in or take out"?

Author Commented:
akshayxx,

Well I m not quite familiar with the grade thing ! i don t know how u grade! but anyway that s what i would have given my self ! coz asking the question made me see some things which helped me to the problem ! well sorry if by mistake I sounded stingy!

Commented:
>but there seems to be a lot fewer questions posted during your "prime time".
I felt that too... however, I am not too sure of this....
>I'm sure that things will normalize the first week of January.
;o)

Boy, you did go to extremes to "teach" her a lesson

>by now the poster is reaping his own rewards and trying to figure out how and engineering degree barely qualifies him to
>ask, "eat in or take out"?
that was her pet peeve, call her a him ... he he

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.