Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Autor: Pawel Koniarski
- // Data: 6 marca 2013 r.
- // Problem: najmniejsza oraz najwieksza z n liczb
- // Plik: nMinMax.cpp
- #include <iostream>
- using namespace std;
- int main()
- {
- // deklaracja zmiennych
- int n;
- int *numbers;
- int i;
- int min;
- int max;
- cout << "Podaj ilosc liczb jakie chcesz sprawdzic: ";
- cin >> n;
- numbers = new int[n]; // tablica dynamiczna
- for (i = 0; i < n; i++)
- {
- cout << "Podaj " << i+1 << " liczbe: ";
- cin >> numbers[i];
- }
- min = numbers[0];
- max = numbers[0];
- for (i = 1; i < n; i++)
- {
- if (numbers[i] < min)
- min = numbers[i];
- if (numbers[i] > max)
- max = numbers[i];
- }
- cout << "\n\nNajmniejsza liczba z podanych to " << min
- << "\nNajwieksza liczba z podanych to " << max << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement