### Determines the highest and lowest

Write an algorithm that determines the highest and lowest among 3 numbers. Assume that the 3 numbers are unique.

Can anyone help me with codes for this problem? thank you
 ``12345678910`` ``````#include int main() { int numbers[3] = {3,5,4}; std::sort(&numbers[0], &numbers[3]); int min = numbers[0]; int max = numbers[2]; }``````

but i dont think that was your task here. you probably need to find the min/max on your own.

edit: forgot &
Last edited on
The highest number and the lowest number should be printed.
I'm going to input for 3 times for each variable.
we are tasked to print the highest and the lowest number among the 3.
 ``12345`` ``````#include int main() { std::cout << min << " " << max; }``````
Hi, i am a begginer too... So i know my code is not perfect (at all) and very long, but it actually works... Just improve it, it might help you :

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
int number[] = {0,0,0};
bool equal = true; int switcher = 0;
srand(time(0));
for (int i=0; i < 3; i++){
number[i] = rand() % 100;
for(int a = 0; a < 3; a++){
if (a!= i && number[a] == number[i] ){
number[i] = rand() % 100;
}
}
}

cout << "numbers : ";
for (int i=0; i < 3; i++){
cout << number[i] << " ";
}
cout << endl << endl;

for (int i=0; i < 3; i++){
for (int x=0; x < 3; x++){
if (number[i] > number[x]){
switcher = number[i];
number[i] = number[x];
number[x] = switcher;
}
}
}

cout << "In order : ";
for (int i=0; i < 3; i++){
cout << number[i] << " ";
}
return 0;
}

@mathalo: maybe you want to try this:

 ``12345678910111213141516171819202122232425`` ``````#include #include #include #include int main() { srand((int)time(0)); int number[3] = {0,0,0}; while(number[0] == number[1] || number[0] == number[2] || number[1] == number[2]) { number[0] = rand() % 100; number[1] = rand() % 100; number[2] = rand() % 100; } std::cout << "numbers : " << number[0] << " " << number[1] << " " << number[2] << std::endl << std::endl; std::sort(number, &number[3]); std::reverse(number, &number[3]); std::cout << "In order : " << number[0] << " " << number[1] << " " << number[2]; }``````
Topic archived. No new replies allowed.