Solved

Comparing !

Posted on 2003-12-11
16
439 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:Kdo
Comment Utility

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
Comment Utility
Kent,
i didnt expect this from you.  this is outright homework problem
0
 

Author Comment

by:Besbous
Comment Utility

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
 
LVL 45

Accepted Solution

by:
Kdo earned 60 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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:Kdo
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 45

Expert Comment

by:Kdo
Comment Utility
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
Comment Utility

 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
Comment Utility
OK I solved the problem! have a good day/night guys !
0
 
LVL 8

Expert Comment

by:akshayxx
Comment Utility
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
Comment Utility
>(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:Kdo
Comment Utility

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
Comment Utility
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
Comment Utility
>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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now