Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //consideram def doua subprograme
- //1 Posmax cu doi parametrii unul v un tablou uni format din n nr intregi de cel mult 3 cifre fiecare si p un nr nat cuprins intre 1 si n sub returneaza val maxima din secventa v[1] pna la v[p]
- //2 schimb 2 par a si b el interschimba val variabilelor reprez de a si b
- //a) scrieti antetul fiecaruia dintre cele 2 subprograme
- //b) scrieti un program care citeste de la tastatua un nr nat n si apoi cele n elementeformate din 3 cifre ficare ale unui tablou unidimensionL.
- //SCRIETI UN PROGRAM CARE SORTEAZA CRESCATOR TABLOUL APELAND SUBPROGRAMELE DESCRISE MAI SUS SI APOI AFISEAZA PE ECRAN .
- #include <iostream>
- using namespace std;
- int pozmax(int v[100],int p)
- {
- int i,max=-99999;
- for (i=1;i<=p;i++)
- if (v[i]>max)
- max=v[i];
- return max;
- }
- int schimba(int &a,int &b)
- {
- swap(a,b);
- }
- int main()
- {
- int v[100],n,i,j;
- cin>>n;
- for (i=1;i<=n;i++)
- cin>>v[i];
- for (i=1;i<n;i++)
- for (j=i;j<=n;j++)
- if (v[i]>v[j])
- schimba(v[i],v[j]);
- for (i=1;i<=n;i++)
- cout<<v[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement