Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. // Wjtektab2.cpp: Określa punkt wejścia dla aplikacji konsoli.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11.     int n;
  12.     const int MAX = 100;
  13.     float A[MAX];
  14.     int nrmin, nrmax;
  15.  
  16.     cout << "Podaj liczbe elementow wektora <=" << MAX << ". " << endl;
  17.     cin >> n;
  18.     if ((n > 0) || (n < MAX))
  19.     {
  20.         for (int i = 0; i < n; i++)
  21.         {
  22.             cout << "Podaj " << i + 1 << " element wektora: " << endl;
  23.             cin >> A[i];
  24.         }
  25.  
  26.         nrmin = 0;
  27.  
  28.         for (int i = 1; i < n; i++)
  29.         {
  30.             if (A[i] < A[nrmin])
  31.                 nrmin = i;
  32.         }
  33.         cout << "Najmniejszy element wynosi: " << A[nrmin] << " i jest na miejscu " << nrmin+1 << endl;
  34.  
  35.         nrmax = 0;
  36.         for (int i = 1; i < n; i++)
  37.         {
  38.             if (A[i] > A[nrmax])
  39.                 nrmax = i;
  40.         }
  41.         cout << "Najwiekszy element wynosi: " << A[nrmax] << " i jest na miejscu " << nrmax + 1 << endl;
  42.  
  43.  
  44.     }
  45.     else
  46.         cout << "Nie da sie utworzyc wektora. " << endl;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement