Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zad 2 min i maksimum wektora.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "");
- int ilosc,i;
- float najwiekszy;
- float najmniejszy;
- int miejsce_m=0;
- int miejsce_w=0;
- cout << "proszę podać ilosc elementow wektora" << endl;
- cin >> ilosc;
- float*wektor = new float[ilosc];
- i = 0;
- do
- {
- cout << "podaj " << i + 1 << " element wektora" << endl;
- cin >> wektor[i];
- i++;
- } while (i < ilosc);
- najmniejszy = wektor[0];
- int b;
- for (b = 0; b < ilosc; b++)
- {
- if (najmniejszy > wektor[b])
- {
- najmniejszy = wektor[b];
- miejsce_m=b;
- }
- }
- cout << "najmniejsza wartość wektora to " << najmniejszy << " i znajduje sie na "<<miejsce_m+1<<" miejscu"<< endl;
- int c;
- najwiekszy = wektor[0];
- for (c = 0; c < ilosc; c++)
- {
- if (najwiekszy < wektor[c])
- {
- najwiekszy = wektor[c];
- miejsce_w=c;
- }
- }
- cout << "najwieksza wartosc wektora to " << najwiekszy << " i znajduje sie na " << miejsce_w+1 << " miejscu" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement