. Write a program, Array Range, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display all the numbers given by the user, the max number, the min number, and the difference

Respuesta :

Answer:

Written in C++

#include<iostream>

using namespace std;

int main() {

int n;

cout<<"Number of array elements: ";

cin>>n;

int myarr[n];

cout<<"Enter array elements: ";

for(int i=0;i<n;i++) {

 cin>>myarr[i];

}

int small = myarr[0];

int larg = myarr[0];

for(int i=0;i<n;i++) {

 if(small > myarr[i]) {

  small = myarr[i];

 }

 if(larg<myarr[i]) {

  larg = myarr[i];

 }

}

cout<<"Array Elements are: ";

for(int i =0; i<n;i++) {

 cout<<myarr[i]<<" ";

}

cout<<endl;

int range = larg - small;

cout<<"Largest: "<<larg<<endl;

cout<<"Smallest: "<<small<<endl;

cout<<"Range: "<<range<<endl;  

return 0;

}

Explanation:

I've added the source file as an attachment where I used comments as explanation

Ver imagen MrRoyal
ACCESS MORE
EDU ACCESS
Universidad de Mexico