Answer to Question #181987 in C++ for python

Question #181987

Write a program to input data into an array (Take value from user at runtime

for inserting into array using loop) and find out the maximum value and minimum value

from array through pointer?


1
Expert's answer
2021-04-16T15:42:01-0400
#include <iostream>
using namespace std;
int main(){
    int *x, count, max = INT_MIN, min = INT_MAX;
    cout<<"How many data items do you want to input?\n";
    cin>>count;
    x = new int[count];
    cout<<"Input data (integers);\n";
    for(int i = 0; i < count; i++){
        cin>>x[i];
        if(x[i] > max) max = x[i];
        if(x[i] < min) min = x[i];
    }


    cout<<"Maximum value = "<<max<<endl;
    cout<<"Minimum value = "<<min<<endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS