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

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 22:55:58 · 4 answers · asked by texas87x 1 in Computers & Internet Programming & Design

4 answers

#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 00:26:06 · answer #1 · answered by iyiogrenci 6 · 0 0

write a loop so that you can look through each of the array elements individually.

(start/loop = c++ for looping, array = contents to search, n = an incremented variable for checking each of the arrays elements)

start loop
array[n]
loop

if you compare the number to another varaible, set default of 0. If the number is bigger stick it in the variable otherwise move on. you can do same thing with the smallest variable.

2007-02-07 23:59:58 · answer #2 · answered by Anonymous · 0 0

Uuuuuh. Whats a function?

2007-02-07 22:58:41 · answer #3 · answered by Zen 2 · 0 0

lol i have never herd of this but i am in 6th grade all i know is pi and those. sorry. if i knew i would tell you.

2007-02-07 23:07:42 · answer #4 · answered by david 2 · 0 0

fedest.com, questions and answers