T is an array of N integers. N is defined as a constant equal to 10.
Write a procedure proc1(int *T) that reads the N elements of the array by checking that the entered values are between 10 and 20. This procedure will display thereafter the N values of the array, the sum value, the maximum value and the minimum value of elements in this array.
#include<iostream>
#include<conio.h>
using namespace std;
#define N 10
void proc1(int *T){
for(int i=0;i<N;i++){
//checking that the entered values are between 10 and 20.
int n=0;
while(n<10 || n>20){
cout<<"Enter number "<<(i+1)<<": ";
cin>>n;
}
T[i]=n;
}
//This procedure will display thereafter the N values of the array,
int sum=0;
int maximum=T[0];
int minimum=T[0];
cout<<"\nThe N values of the array: \n";
for(int i=0;i<N;i++){
cout<<T[i]<<" ";
sum+=T[i];
if(T[i]>maximum){
maximum=T[i];
}
if(T[i]<minimum){
minimum=T[i];
}
}
//the sum value, the maximum value and the minimum value of elements in this array.
cout<<"\nThe sum value: "<<sum<<"\n";
cout<<"The maximum value: "<<maximum<<"\n";
cout<<"The minimum value: "<<minimum<<"\n";
}
int main()
{
int *T=new int[N];
proc1(T);
cin>>T[0];
return 0;
}
Comments
Leave a comment