English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I got this exercise for homework, but i have no clue how to do it... PLEASE HELP ME !, thanks for all answers!

Write a C++ program that finds the position of the smallest and largest number in an array of double. Use a function

void slposition (double[ ] array, int& psmallest, int size)

to do it. Here the size is the size of the array. Thanks for all the help i can get !. Yes it is my homework, i tried but dont know how to do it... HELP ME !!!!!!!

2007-02-07 23:12:49 · 9 answers · asked by texas87x 1 in Computers & Internet Programming & Design

9 answers

http://answers.yahoo.com/question/index;_ylt=Ajb3c2BglE.CADpaNtV.XTty7hR.?qid=20070208035926AA2DR4B

2007-02-07 23:23:55 · answer #1 · answered by Anonymous · 0 0

Go through the array. Have two variables.
double smallest = MAX_DOUBLE_VALUE; //Get this from the limits.h include file. I'm not sure if that's the exact way to do it, but that's it.
double largest = MIN_DOUBLE_VALUE; //Same as for MAX.

The reason you do the min and the max for the opposite variables is that you are guaranteed to change them then, no matter the number range.

int lcv = 0;
int position_smallest;
int position_largest;

int array_length = sizeof(array) / sizeof(array[0];

for( ; lcv < array_length; lcv++)
{
if(array[lcv] < smallest)
{
smallest = array[lcv];
position_smallest = lcv;
}
if(array[lcv] > largest)
{
largest = array[lcv];
position_largest = lcv;
}
}

There you go, now your two variables position_smallest and position_largest have the positions of the numbers you are looking for.

Hope it helps! If you have any more questions about the code, I'd be more than happy to help.

2007-02-08 07:20:15 · answer #2 · answered by Anonymous · 0 1

Your life is NOT on the line. The problem here is that you've been too lazy to do your own homework, and now you want someone else to do it for you otherwise you'll get in trouble. Why not either:

a) Take it like a man
or
b) Get your *** in gear and learn to code

instead of lying to the people you are asking for help.

2007-02-08 07:39:09 · answer #3 · answered by Anonymous · 0 0

#include
using namespace std;

void slposition (double b[], int size)
{
int i;
double small=b[0];
double big=b[0];
int smallindex=0;
int bigindex=0;
for(i=1;i if (small > min(small,b[i])) smallindex=i;
if (big < max(big,b[i])) bigindex=i;
}
cout << "\n position of the smallest : " << smallindex;
cout << "\n position of the largest : " << bigindex;
return;
}

main () {
double a[10];
int n,i;

while(true){

system("cls");
cout << "\nEnter number of the elements :";
cin >> n;
for(i=0;i cout << "\nEnter element " << i << " : ";
cin >> a[i];
}
slposition (a,n);
cout << endl << endl;
system("pause");
}
}

2007-02-08 08:15:26 · answer #4 · answered by iyiogrenci 6 · 0 0

MAX=-1;
MIN=9999;
for(int i+0; i {
if (array[i]>max)
max=array[i];
locationmax = i;
if (array[i] min=array[i];
locationmin = i;
}
implement this this should help.

2007-02-08 08:33:05 · answer #5 · answered by Mitch 1 · 0 0

we dont solve exercise work here. what is the specific problem that u are facing in programjming

2007-02-08 07:36:26 · answer #6 · answered by The Saint 1 · 1 0

Cheating on life eh?

2007-02-08 07:25:02 · answer #7 · answered by Mafia Agent 4207 5 · 1 0

Is your life really on the line?

2007-02-08 07:20:57 · answer #8 · answered by DARIA. - JOINED MAY 2006 7 · 1 0

cheater!

2007-02-08 07:21:10 · answer #9 · answered by Anonymous · 1 0

fedest.com, questions and answers