Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. // Zad 2 min i maksimum wektora.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "");
  13.     int ilosc,i;
  14.     float najwiekszy;
  15.     float najmniejszy;
  16.     int miejsce_m=0;
  17.     int miejsce_w=0;
  18.  
  19.     cout << "proszę podać ilosc elementow wektora" << endl;
  20.     cin >> ilosc;
  21.     float*wektor = new float[ilosc];
  22.  
  23.     i = 0;
  24.  
  25.     do
  26.     {
  27.         cout << "podaj " << i + 1 << " element wektora" << endl;
  28.         cin >> wektor[i];
  29.         i++;
  30.     } while (i < ilosc);
  31.  
  32.         najmniejszy = wektor[0];
  33.     int b;
  34.     for (b = 0; b < ilosc; b++)
  35.     {
  36.         if (najmniejszy > wektor[b])
  37.         {
  38.             najmniejszy = wektor[b];
  39.             miejsce_m=b;
  40.            
  41.         }
  42.        
  43.         }
  44.     cout << "najmniejsza wartość wektora to " << najmniejszy << " i znajduje sie na "<<miejsce_m+1<<" miejscu"<< endl;
  45.     int c;
  46.     najwiekszy = wektor[0];
  47.     for (c = 0; c < ilosc; c++)
  48.     {
  49.         if (najwiekszy < wektor[c])
  50.         {
  51.             najwiekszy = wektor[c];
  52.             miejsce_w=c;
  53.            
  54.         }
  55.        
  56.     }
  57.     cout << "najwieksza wartosc wektora to " << najwiekszy << " i znajduje sie na " << miejsce_w+1 << " miejscu" << endl;
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement