Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I_parcijalni_ispit_2014 Zadatak_3 */
- #include <iostream>
- #include <vector>
- #include <stdexcept>
- using std::cin;
- using std::cout;
- using std::endl;
- void UnesiMatricu(std::vector<std::vector<double>> &a)
- {
- for(unsigned int i(0); i < a.size(); i++)
- {
- for(unsigned int j(0); j < a[i].size(); j++)
- {
- std::cout << "Unesite element (" << i+1 << ", " << j+1 << "): ";
- std::cin >> a[i][j];
- }
- }
- }
- void funkcija (std::vector<std::vector<double>> m, double &minimax, double &maximin)
- {
- for(int i = 1; i < m.size(); i++)
- if(m[0].size() != m[i].size())
- throw std::domain_error("Parametar nema formu matrice");
- double temp;
- for(int i = 0; i < m.size(); i++) {
- for(int j = 1; j < m[i].size(); j++) {
- temp = m[i][0];
- if (m[i][j] > temp) temp = m[i][j];
- }
- if (i == 0) minimax = temp;
- else if(temp < minimax) minimax = temp;
- }
- for(int i = 0; i < m.size(); i++) {
- for(int j = 1; j < m[i].size(); j++) {
- temp = m[i][0];
- if (m[i][j] < temp) temp = m[i][j];
- }
- if (i == 0) maximin = temp;
- else if (temp > maximin) maximin = temp;
- }
- }
- int main()
- {
- double najmanjiMaks, najveciMin;
- std::vector<std::vector<double>> vektorVektora(3, std::vector<double>(2)); // matrica 3x2
- UnesiMatricu(vektorVektora);
- try {
- funkcija(vektorVektora, najmanjiMaks, najveciMin);
- cout << "minimax: " << najmanjiMaks << " maximin: " << najveciMin << endl;
- }
- catch(std::domain_error(izuzetak)) {
- cout << izuzetak.what();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement