maximul unui vector

Se citeste un vector cu n componente numere intregi.Se cere sa se afiseze valoarea maxima folosind metoda divide et impera

#include<iostream.h>
int v[100],n;

int max(int i,int j)
{
int a,b;
if(i==j) return v[i];
else
{
a=max(i,(i+j)/2);
b=max((i+j)/2+1,j);
if(a>b) return a;
else return b;
}
}

void main()
{
cout<<“n=”;cin>>n;
for(int i=0;i<n;i++)
{
cout<<“v[“<<i<<“]=”;
cin>>v[i];
}
cout<<“maximul este:”<<max(0,n-1);
}

{joscommentenable}

maximul unui vector

Se citeste un vector cu componente numere intregi.Se cere sa se afiseze cel mai mare numar intreg gasit.

#include<iostream.h>
int v[10],n,i,max;
void main()
{
cout<<“n=”;cin>>n;
for(i=0;i<n;i++)
{
cout<<“v[“<<i<<“]=”;
cin>>v[i];
}
max=v[0];
for(i=1;i<n;i++)
if(v[i]>max) max=v[i];
cout<<“max=”<<max;
}

maximul a n componente

Maximul unui vector

#include<iostream.h>
#include<conio.h>
typedef int vector[20];
int n;vector v;

int maxim(int n)
{int max;
if (n==1) return v[1];
else
{
max=maxim(n-1);
if (max<v[n]) return v[n];
else return max;
}
}

void main()
{
cout<<“n=”;cin>>n;
for(int i=1;i<=n;i++)
{cout<<“v[“<<i<<“]=”;cin>>v[i];}
cout<<maxim(n)<<endl;
getch();
}

{module orizontal600}