Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "fstream"
- #include "iomanip"
- using namespace std;
- int main(int argc, char* argv[])
- {
- const int nmax = 20;
- float wektor[nmax];
- int a = 1, instr, pozmin, pozmax;
- while (1)
- {
- int n, i;
- float min, max;
- cout << "Podaj rozmiar wektora n(<=" << nmax << ")" << endl;
- cin >> n, i;
- if (n > 0 && n <= nmax)
- {
- for (i = 0; i < n;i++)
- {
- cout << "Podaj wektor [" << i + 1 << "]" << endl;
- cin >> wektor[i];
- }
- cout << "Wektor ma postac:" << endl;
- for (i = 0; i < n; i++)
- cout << setw(8) << setprecision(2) << fixed << wektor[i] << " ";
- cout << endl;
- cout << "Wybierz sposob obliczania:1 lub 2" << endl;
- cin >> instr;
- switch (instr)
- {
- case 1:
- min = wektor[0];
- for (i = 1;i < n;i++)
- if (wektor[i] < min)
- {
- min = wektor[i];
- max = wektor[0];
- pozmin = i + 1;
- }
- else
- {
- max = wektor[0];
- if (max < wektor[i])
- {
- max = wektor[i];
- pozmax = i + 1;
- }
- else
- {
- max;
- pozmax = i + 1;
- }
- }
- cout << "wartosc minimalna w wektorze wynosi:" << min << endl;
- cout << "Jest na pozycji:" << pozmin << endl;
- cout << "wartosc maksymalna w wektorze wynosi:" << max << endl;
- cout << "Jest na pozycji:" << pozmax << endl;
- break;
- case 2:
- int nrmin = 0;
- int nrmax;
- for (i = 1;i < n;i++)
- if (wektor[i] < wektor[nrmin])
- {
- nrmin = i;
- nrmax = 0;
- }
- else
- {
- nrmax = 0;
- if (wektor[nrmax] < wektor[i])
- {
- nrmax = i;
- }
- else
- nrmax;
- }
- cout << "wartosc minimalna w wektorze wynosi" << wektor[nrmin] << endl;
- cout << "wartosc maksymalna w wektorze wynosi:" << wektor[nrmax] << endl;
- break;
- }
- }
- else
- cout << "Zly rozmiar wektora" << endl;
- cout << "Aby ponownie uruchomic program podaj dowolna liczbe, zas aby wyjsc z programu podaj 0" << endl;
- cin >> a;
- if (a == 0)
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement