Source Code:
#include<iostream>
using namespace std;
int main()
{
int a[10],n,i;
cout<<"Enter the no.of elements you wish to store in an array: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter element"<<" "<<(i+1)<<":";
cin>>a[i];
}
for(i=1;i<n;i++)
{
if(a[0]<a[i])
{
a[0]=a[i];
}
}
cout<<"Therefore the maximum element of the array is: "<<a[0];
}
#include<iostream>
using namespace std;
int main()
{
int a[10],n,i;
cout<<"Enter the no.of elements you wish to store in an array: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter element"<<" "<<(i+1)<<":";
cin>>a[i];
}
for(i=1;i<n;i++)
{
if(a[0]<a[i])
{
a[0]=a[i];
}
}
cout<<"Therefore the maximum element of the array is: "<<a[0];
}
Program Output:
0 Comments