Advertisement
artur99

Exemplu vectori C++

Dec 16th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. // se citește n de la tastatură, apoi n numere,
  4. // să se calculeze de câte ori apare în șir numărul maxim
  5. // 8
  6. // 3 7 4 7 3 1 2 6
  7.  
  8. int main() {
  9.     int a[1005], n, i, max, c;
  10.  
  11.     cin>>n;
  12.  
  13.     for(i = 1; i <= n; i++) {
  14.         cin>>a[i];
  15.     }
  16.  
  17.     max = a[1];
  18.     for(i = 1; i <= n; i++) {
  19.         if(a[i] > max) {
  20.             max = a[i];
  21.         }
  22.     }
  23.  
  24.     c = 0;
  25.     for(i = 1; i <= n; i++) {
  26.         if(max == a[i]) {
  27.             c ++;
  28.         }
  29.     }
  30.  
  31.     cout<<c<<endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement