Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
 
PREVIOUS NEXT
Tagged: #minimum #array
ADD COMMENT
Topic
Name
2+6 =