c++ max of array
cout << " max element is: " << *max_element(array , array + n) << endl;
c++ max of array
cout << " max element is: " << *max_element(array , array + n) << endl;
minimum value in array using c++
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
double array[6];
double min=array[6];
double max=array[0];
int indexOfMin=0;
int indexOfMax=0;
srand (time(0));
for(int i=0;i<6;i++){
array[i] = rand()%30;
cout<<"Element "<<i<<": ";
cout<<array[i]<<endl;
if(array[i]>max){
max=array[i];
indexOfMax=i;
}
if(array[i]<min){
min=array[i];
indexOfMin=i;
}
}
cout<<"The minimum value is "<<min<<endl;
cout<<"The index of the minimum value is "<<indexOfMin<<endl;
cout<<"The maximum value is "<<max<<endl;
cout<<"The index of the maximum value is "<<indexOfMax<<endl;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us