Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Mic9.cpp: Określa punkt wejścia dla aplikacji konsoli.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "");
- const int nmax = 100;
- int n, i, j, wmin, wmax;
- float pom;
- wmin = wmax = 0;
- wmax = wmin = 0;
- cout << "Podaj liczbę elementów wektora (n<=" << nmax << ")" << endl;
- cin >> n;
- if (n > 0 && n <= nmax)
- {
- float wektor[nmax];
- for (i = 0; i < n; i++) //wprowadzanie wartości
- {
- cout << "Podaj " << i << " element" << endl;
- cin >> wektor[i];
- }
- for (i=0; i < n; i++) //szukanie najmniejszej
- {
- if (wektor[wmin]>wektor[i])
- wmin = i;
- else
- if (wektor[wmax] < wektor[i])
- wmax = i;
- }
- cout << "Najmniejszy element wynosi " << wektor[wmin] << " dla " << wmin + 1 << " elementu" << endl;
- cout << "Największy element wynosi " << wektor[wmax] << " dla " << wmax + 1 << " elementu" << endl;
- for (i = 0; i < n - 1; i++)
- {
- wmin = i;
- for (j = i + 1; j < n; j++)
- if (wektor[j] < wektor[wmin])
- wmin = j;
- pom = wektor[i];
- wektor[i] = wektor[wmin];
- wektor[wmin] = pom;
- }
- cout << "Wektor posortowany:";
- for (i = 0; i < n; i++)
- {
- cout << wektor[i] << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement