Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int find_min_positive(int[], size_t, size_t &);
- int main() {
- int arr[] = { 9, -2, 3, 4, 5, -9, 11, 2, -1 };
- size_t index = 0;
- if (find_min_positive(arr, 9, index) != 0)
- cout << "Minimum positive element in the array is " << find_min_positive(arr, 9, index) << " and its index is " << index << endl;
- else
- cout << "No positive elements in the array!\n";
- return 0;
- }
- int find_min_positive(int array[], size_t array_size, size_t &array_index) {
- size_t counter = 0;
- for (size_t i = 0; i < array_size; i++)
- if (array[i] > 0) {
- array_index = i;
- counter++;
- }
- if (counter == 0)
- return 0;
- int min = array[array_index];
- for (size_t i = 0; i < array_size; i++)
- if (min > array[i] && array[i] > 0) {
- min = array[i];
- array_index = i;
- }
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement