Created
May 20, 2012 17:02
-
-
Save salvianoo/2758773 to your computer and use it in GitHub Desktop.
n7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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