Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ take n number from the user and store them in array and get the max, min number of them and also find the average/summation of these numbers

#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; 
	
}
Source by www.assignmentexpert.com #
 
PREVIOUS NEXT
Tagged: #number #user #store #array #min #number #find #numbers
ADD COMMENT
Topic
Name
3+6 =