Yesterday I went for an interview where I have been asked to create a program to find largest and smallest among 5 numbers without using array.
I know how to create
Heres what I did, without using an array. This was a method to return the highest number of 5 scores.
double findHighest(double score1, double score2, double score3, double score4, double score5)
{
double highest = score1;
if (score2 > score1 && score2 > score3 && score2 > score4 && score2 > score5)
highest = score2;
if(score3 > score1 && score3 > score2 && score3 > score4 && score3 > score5)
highest = score3;
if(score4 > score1 && score4 > score2 && score4 > score3 && score4 > score5)
highest = score4;
if (score5 > score1 && score5 > score2 && score5 > score3 && score5 > score4)
highest = score5;
return highest;
}
An array is going to be far more efficient, but I had to do it for homework without using an array.