Answer to Question #156081 in C++ for zain ul abdeen

Question #156081

Write a program which takes 10 numbers from the user and store them in an array and find the average, Largest and smallest number in the array


1
Expert's answer
2021-01-17T08:09:35-0500
#include <iostream>
using namespace std;
int main(){
	int arr[10], n=10, i, max, min,avg;
	cout <<"Enter the numbers ";
	for(i=0;i<n;i++){
		cin >> arr[i];
	}	
	// for maximum value
	max = arr[0];
	for (i=0;i<n;i++){
		if (max < arr[i]){
			max = arr[i];
		}
	}
	// for minimum value
	min = arr[0];
	for (i=0;i<n;i++){
		if (min > arr[i]){
			min = arr[i];
		}
	}
	// average 
	int sum = 0;
	for (i=0;i<n;i++){
		sum += arr[i];
	}
	avg = sum/n;

	cout<<"Maximum number is :"<< max<<endl ;
	cout <<"Minimum number is :"<<min<<endl;
	cout<<"Average of numbers :"<< avg; 
	
}

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
APPROVED BY CLIENTS