Link to home
Start Free TrialLog in
Avatar of Besbous
Besbous

asked on

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
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image


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
Kent,
i didnt expect this from you.  this is outright homework problem
Avatar of Besbous
Besbous

ASKER


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]);
     
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Besbous

ASKER

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 ! :(!
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
Avatar of Besbous

ASKER

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

And as you've probably gathered, we're a bit paranoid about providing answers to homework.  This link will help you to understand why:

https://www.experts-exchange.com/questions/20690354/help-me-program-convert-file-to-a-plain-c-program.html


Anyway, glad that we could help
Kent
Avatar of Besbous

ASKER


 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 !
Avatar of Besbous

ASKER

OK I solved the problem! have a good day/night guys !
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
>(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 ?

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"?




Avatar of Besbous

ASKER

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!

>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