Find the best answers to your questions at Westonci.ca, where experts and enthusiasts provide accurate, reliable information. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals.
Sagot :
Answer:
The program in C++ is as follows:
#include <iostream>
#include <iomanip>
using namespace std;
int* sortArray(int temp [], int n){
int tmp;
for(int i = 0;i < n-1;i++){
for (int j = i + 1;j < n;j++){
if (temp[i] > temp[j]){
tmp = temp[i];
temp[i] = temp[j];
temp[j] = tmp; } } }
return temp;
}
float average(int temp [], int n){
float sum = 0;
for(int i = 0; i<n;i++){
sum+=temp[i]; }
return sum/n;
}
int main(){
int n;
cout<<"Number of temperatures: "; cin>>n;
while(n>10){
cout<<"Number of temperatures: "; cin>>n; }
int temp[n];
for(int i = 0; i<n;i++){
cout<<"Input temperature "<<i+1<<": ";
cin>>temp[i]; }
int *sorted = sortArray(temp, n);
cout<<"The sorted temperature in ascending order: ";
for( int i = 0; i < n; i++ ) { cout << *(sorted + i) << " "; }
cout<<endl;
float ave = average(temp,n);
cout<<"Average Temperature: "<<setprecision(2)<<ave<<endl;
cout<<"Highest Temperature: "<<*(sorted + n - 1)<<endl;
cout<<"Lowest Temperature: "<<*(sorted + 0)<<endl;
return 0;
}
Explanation:
See attachment for complete source file with explanation
Thank you for trusting us with your questions. We're here to help you find accurate answers quickly and efficiently. We appreciate your time. Please come back anytime for the latest information and answers to your questions. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.