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
1 2 3 4 5 6 7 8 9 10

#include<algorithm>
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.
we don't do your homework here... please try to write your own code at first place...
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;
}