Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

minimum or maximum in array c++

#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
 
int main()
{
    int arr[] = { 4, 2, 1, 6, -8, 5 };
 
    int min = INT_MAX, max = INT_MIN;
    for (int i: arr)
    {
        if (i < min) {
            min = i;
        }
 
        if (i > max) {
            max = i;
        }
    }
 
    std::cout << "The min element is " << min << std::endl;
    std::cout << "The max element is " << max << std::endl;
 
    return 0;
}
Comment

minimum or maximum in array 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;
}

Comment

PREVIOUS NEXT
Code Example
Cpp :: what does the modularity mean in c++ 
Cpp :: iterate over 2 vectors c++ 
Cpp :: remove element from array c++ 
Cpp :: strlen in c++ 
Cpp :: how to add an element to std::map 
Cpp :: how to rotate canvas android 
Cpp :: c++ isalphanum 
Cpp :: c++ clear char array 
Cpp :: c++ binary search 
Cpp :: built in factorial function in c++ 
Cpp :: c++ friend class 
Cpp :: check if whole string is uppercase 
Cpp :: uses of gamma rays 
Cpp :: create copy constructor c++ 
Cpp :: std::iomanip c++ 
Cpp :: how to sort in c++ 
Cpp :: c++ int to char* 
Cpp :: how to read files in c++ 
Cpp :: iterate through map c++ 
Cpp :: currency converter c++ 
Cpp :: What is the "--" operator in C/C++? 
Cpp :: c++ map insert 
Cpp :: factorial calculator c++ 
Cpp :: c++ initialize a vector 
Cpp :: print counting in c++ 
Cpp :: how to say hello world in c++ 
Cpp :: cpp map insert 
Cpp :: string format decimal places c++ 
Cpp :: c++ integer array 
Cpp :: overload subscript operator cpp 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =