Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Comparing !

Posted on 2003-12-11
16
444 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:Besbous
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9919816

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
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 9919890
Kent,
i didnt expect this from you.  this is outright homework problem
0
 

Author Comment

by:Besbous
ID: 9919946

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]);
     
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
LVL 45

Accepted Solution

by:
Kent Olsen earned 60 total points
ID: 9920054
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
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 40 total points
ID: 9920073
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
0
 

Author Comment

by:Besbous
ID: 9920169
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 ! :(!
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9920209
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
0
 

Author Comment

by:Besbous
ID: 9920261
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 !
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9920337
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:

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


Anyway, glad that we could help
Kent
0
 

Author Comment

by:Besbous
ID: 9920409

 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 !
0
 

Author Comment

by:Besbous
ID: 9922102
OK I solved the problem! have a good day/night guys !
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 9926294
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
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9926371
>(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 ?
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9927914

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




0
 

Author Comment

by:Besbous
ID: 9929194
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!

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9933030
>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

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question