I am writing a small program in which I have to search for smallest and largest element entered.
The thing is I have made an array 10 elements wide and the user should enter at least 5 element.
If the user enter less than 5 elements I want to prompt insufficient elements.
This is the code I have written but it's not working:
#include <iostream>
using namespace std;
int main()
{
int arr[10], largest, smallest, i = 1, j = 1;
cout << "Enter the values in array at least 5 and maximum 10 " << endl;
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
while (arr[i] >= 5)
{
largest = arr[0];
smallest = arr[0];
if (largest <= arr[j])
{
largest = arr[j];
}
if (smallest > arr[j])
{
smallest = arr[j];
}
j++;
i++;
}
getch();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire