I am trying this code..bt it is giving garbage value as maximum element of an array.can anybody help me plzz
{
int no_ele;
cin>>no_ele;
cout<<"Number of elements:"<<no_ele<<"\n";
int ele_array[no_ele];
for(int i=1;i<=no_ele;i++)
{
cin>>ele_array[i];
}
int max;
int min;
max=ele_array[0];
min=ele_array[0];
for(int i=0;i<no_ele;i++)
{
if(ele_array[i]<min)
{
min=ele_array[i];
}
else if(ele_array[i]>max)
{
max=ele_array[i];
}
}
cout<<"Maximum Value:"<<max;
cout<<"Minimum Value:"<<min;
}
You read the values into the array incorrectly. Your for loop should be for(int i = 0; i < no_ele; ++i)
Thanks...its working...:-)