Advertisement
STANAANDREY

nr_ap_elem

Apr 14th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  int v[1000],k,n,i,j,aux;
  7.  cout<<"n=";cin>>n;
  8.  for (i=0;i<n;i++) {
  9.   cin>>v[i];
  10.  }
  11.  k=0;
  12. for (i=0;i<n-1;i++)
  13. for (j=i+1;j<n;j++)
  14.     if (v[i]>v[j])
  15. {
  16.     aux=v[i];
  17.     v[i]=v[j];
  18.     v[j]=aux;
  19. }
  20. k=1;v[n]=v[n-1]+1;
  21. for (i=1;i<=n;i++)
  22.     if (v[i]==v[i-1])
  23.     k++;
  24.     else
  25. {
  26.         cout<<v[i-1]<<' '<<k<<endl;
  27.         k=1;
  28. }
  29. //*/
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement