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?
#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;
}
Comments
Leave a comment