Jump to content

Recommended Posts

  • Moderators
Posted

Prima mea problemuţă cu vectori, so nu vă panicaţi scarytv.gif

 

Se citesc n numere întregi. Să se afişeze cea mai mare valoare citită şi de câte ori apare.

 

Se poate ceva mai bine faţă de codul de mai jos? :D

#include <iostream>
#define rmax 1000
using namespace std;
int main()
{
    int n,x,a[rmax],max=0,s=0,iv,i;
    cin>>n;
    for (i=0;i<n;i++)
    {
         cin>>x;
         a[i]=x;
         if (x>max)
                 max=x;
    }
    for (iv=0;iv<n;iv++)
         if (a[iv]==max)
                 s++;
    cout<<endl<<max<<endl<<s;
    return 0;
}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.