Răspuns :
Ex. 2.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n,i,max=0,min=999999999,x;
cout<<"Introdu lungimea sirului: ";
cin>>n;
cout<<"Introdu elementele sirului: "<<endl;
for(i=1;i<=n;i++)
{
cin>>x;
if(x>max)
{
max=x;
}
if(x<min)
{
min=x;
}
}
cout<<"Nr. maxim din sir este: "<<max<<", iar nr. minim este: "<<min;
}
Ex.3.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b;
cout<<"Introduce inceputul intervalului: "<<endl;
cin>>a;
cout<<"Introduce sfarsitul intervalului: "<<endl;
cin>>b;
cout<<"In interval se afla: "<<b-a<<" elemente";
}
Ex. 4.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int k,i,sir;
cout<<"Introdu nr. k: "<<endl;
cin>>k;
cout<<"Introdu lungimea sirului: "<<endl;
cin>>sir;
int array[sir];
cout<<"Introdu elementele sirului: "<<endl;
for(i=0;i<sir;i++)
{
cin>>array[i];
}
cout<<k<<" apare in pozitiile: ";
for(i=0;i<sir;i++)
{
if(array[i]==k)
{
cout<<i<<",";
}
}
}