-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Operations.cpp
More file actions
44 lines (37 loc) · 991 Bytes
/
Copy pathArray_Operations.cpp
File metadata and controls
44 lines (37 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 1:Write a program to create an array of integers and perform following operations on that array like
// finding the sum, average, maximum and minimum number in that array. Accept the numbers of the
// array from user.
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Enter size of an array = ";
cin >> size;
int sum = 0;
float average = 0;
int min = INT_MAX;
int max = INT_MIN;
int array[size];
for (int i = 0; i < size; i++)
{
cin >> array[i];
}
for (int i = 0; i < size; i++)
{
if (array[i] > max)
{
max = array[i];
}
if (array[i] < min)
{
min = array[i];
}
sum = sum + array[i];
}
average = static_cast<float>(sum / size);
cout << "Sum of array is = " << sum;
cout << "\nAverage of array is = " << average;
cout << "\nMaximum number is = " << max;
cout << "\nMinimum number is = " << min;
}