Advertisement
lewapkon

nMinMax

Mar 6th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. //  Autor: Pawel Koniarski
  2. //  Data: 6 marca 2013 r.
  3. //  Problem: najmniejsza oraz najwieksza z n liczb
  4. //  Plik: nMinMax.cpp
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     // deklaracja zmiennych
  13.     int n;
  14.     int *numbers;
  15.     int i;
  16.     int min;
  17.     int max;
  18.    
  19.     cout << "Podaj ilosc liczb jakie chcesz sprawdzic: ";
  20.     cin >> n;
  21.     numbers = new int[n]; // tablica dynamiczna
  22.    
  23.     for (i = 0; i < n; i++)
  24.     {
  25.         cout << "Podaj " << i+1 << " liczbe: ";
  26.         cin >> numbers[i];
  27.     }
  28.    
  29.     min = numbers[0];
  30.     max = numbers[0];
  31.     for (i = 1; i < n; i++)
  32.     {
  33.         if (numbers[i] < min)
  34.             min = numbers[i];
  35.         if (numbers[i] > max)
  36.             max = numbers[i];
  37.     }
  38.    
  39.     cout << "\n\nNajmniejsza liczba z podanych to " << min
  40.          << "\nNajwieksza liczba z podanych to " << max << endl;
  41.          
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement