Está en la página 1de 1

//encuentra recursivamente el maximo elemento de un array #include <iostream> const int MAX=20; int max(int n,int x[]); using

namespace std; int main() //recur8.cpp E. Raffo Lecca { int x[MAX], n; cout<<"Cuantos elementos en el array? "; cin>>n; for (int i=0; i<n; i++) cin>>x[i]; cout<<"El maximo elemento es: "<<max(n,x)<<endl; system("PAUSE"); return 0; } int max(int n,int x[]) { if(n==1) return x[0]; if(x[n-1]>max(n-1,x)) return x[n-1]; else return max(n-1,x); }

También podría gustarte