👤

Într–un tablou de N numere întregi de găsit elementul maximal şi de schimbat cu primul element.

Răspuns :

#include <iostream>
using namespace std;
int main(){    int n, maxi, imax, vect[100];    cin>>n;    for(int i=1; i<=n; i++)        cin>>vect[i];
    maxi =vect[1];    imax = 1;    for(int i=1; i<=n; i++) {        if (vect[i]>maxi) {            maxi = vect[i];            imax = i;        }    }
    int aux = vect[1];    vect[1]= vect[imax];    vect[imax] = aux;
    for(int i=1; i<=n; i++)        cout<<vect[i]<<" ";    return 0;}
Vezi imaginea PASSBRAIN123