Skip to content

Instantly share code, notes, and snippets.

@salvianoo
Created May 20, 2012 17:02
Show Gist options
  • Save salvianoo/2758773 to your computer and use it in GitHub Desktop.
Save salvianoo/2758773 to your computer and use it in GitHub Desktop.
n7
//n7
#include <iostream>
#include <vector>
using namespace std;
int maxValue(vector<int> &array) {
int size = array.size();
int max = array[0];
for (int i = 0; i < size; i++) {
if (array[i] != 0 && array[i] > max) {
max = array[i];
}
}
return max;
}
int minValue(vector<int> &array) {
int size = array.size();
int min = array[0];
for (int i = 0; i < size; i++) {
if (array[i] != 0 && array[i] < min) {
min = array[i];
}
}
return min;
}
int main (int argc, char * const argv[]) {
vector<int> array;
int num;
do {
cout << "Insira um valor (0 para finalizar) : ";
cin >> num;
array.push_back(num);
} while (num != 0);
cout << "Maior valor digitado: " << maxValue(array) <<endl;
cout << "Menor valor digitado: " << minValue(array) <<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment