I have created a program which takes in the user input for a couple of things and sorts them out in an array. The problem is, I would like to print the highest and lowest numbers in the array.
#include<iostream>
#define CONSTANT 1000000L //this is a constant (it's value is higher than an integer value (32767)
usingnamespace std;
int v[100], i, highest=0, lowest=0, n;
int main()
{
cout<<"The length of the array is: ";
cin>>n;
for(i=1; i<=n; i++)
{ cout<<"v["<<i<<"]=";
cin>>v[i];
}
highest=v[1];
lowest=CONSTANT;
for(i=1; i<=n; i++) //the loop which performs the conditions
{
if(highest<v[i]) //condition #1
{
highest=v[i];
}
if(lowest>v[i]) //condition #2
{
lowest=v[i];
}
}
cout<<"The highest element in that array is: "<<highest<<"\n";
cout<<"The lowest element in that array is: "<<lowest;
return (0);
}