Q.
Write an program that takes an array of integers as input and performs following
operations
-Find sum of all elements in array
-Find max. and min. values in the array
-sort the array in ascending order
#include <iostream>
#include <algorithm>
int main()
int n;
std::cout << "Enter the size of the array: ";
std::cin >> n;
int arr[n];
std::cout << "Enter the elements of the array:\n";
for (int i = 0; i < n; i++)
std::cin >> arr[i];
// Calculate the sum of all elements
int sum = 0;
for (int i = 0; i < n; i++)
sum += arr[i];
std::cout << "Sum of all elements: " << sum << std::endl;
// Find the maximum and minimum values
int maxVal = arr[0];
int minVal = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > maxVal)
maxVal = arr[i];
if (arr[i] < minVal)
minVal = arr[i];
std::cout << "Maximum value: " << maxVal << std::endl;
std::cout << "Minimum value: " << minVal << std::endl;
// Sort the array in ascending order
std::sort(arr, arr + n);
std::cout << "Sorted array in ascending order: ";
for (int i = 0; i < n; i++)
std::cout << arr[i] << " ";
std::cout << std::endl;
return 0;