Răspuns :
Răspuns:
#include <iostream>
using namespace std;
int main()
{ int n,i,j,t,a[200];
cout<<"n= "; cin>>n;
cout<<"Introduceti elementele vectorului"<<endl;
for(i=1;i<=n;i++) cin>>a[i];
cout<<"t= "; cin>>t;
for (i=1;i<t;i++)
for(j=i+1;j<=t;j++)
if(a[i]>a[j]){int aux=a[i]; a[i]=a[j]; a[j]=aux;}
cout<<"Vectorul cu primele "<<t<<" elemente sortate crescator: "<<endl;
for (i=1;i<=n;i++)
cout<<a[i]<<" ";
return 0;
}
Explicație:
Am presupus ca se introduce un t<=n.
Răspuns:
#include<bits/stdc++.h>
using namespace std;
int v[1000], i, t, j, n;
int main()
{
cin>>n>>t;
for (i=0; i<n; i++)
cin>>v[i];
sort(v, v+t);
for (i=0; i<t; i++)
cout<<v[i]<<" ";
return 0;
}