1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
//============================================================================
// Name : findLowest.cpp
// Author : Ironman
// Version :
// Copyright : Your copyright notice
// Description : lowestValueFinder
//============================================================================
#include <iostream>
using namespace std;
int main()
{
int myArray[20] = {10, 120, 70, 99, 4, 15, 83, 9, 13, 64, 28, 57, 69, 43, 2, 17, 72, 19, 94, 101}; //array
int arraySize = 20; //array size
int howManySmallValues = 4; //how many smaller numbers are you looking for
int minLimit = (arraySize-howManySmallValues); //minimum number of times the element has to be smaller than other array elements
//to be considered as one of smallest
//sets current array element
for(int y = 0; y < arraySize; y++)
{
int isSmaller = 0; // remembers the number of times when the current element value was smaller than other element value
//compares current array element with every element in the array
for(int x = 0 ; x < arraySize; x++)
{
if(myArray[y]<myArray[x]){ //if the current element is smaller than other element value add 1 to isSmaller variable
isSmaller++;
}
}
//if element was smaller than other elements same or more times than the minLimit print that element as one among smallest
if (isSmaller >= minLimit)
{
cout << myArray[y] << endl;
}
}
}
|