[go: up one dir, main page]

0% found this document useful (0 votes)
24 views1 page

D Que1.cpp

The document contains C++ code that defines functions to find the maximum and minimum elements in an array. It also includes functions to display the array and its statistics. The main function demonstrates these functionalities using a sample array.

Uploaded by

sidgft1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

D Que1.cpp

The document contains C++ code that defines functions to find the maximum and minimum elements in an array. It also includes functions to display the array and its statistics. The main function demonstrates these functionalities using a sample array.

Uploaded by

sidgft1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// findMax function should return maximum element of array

// findMin function should return minimum element of array


#include <bits/stdc++.h>
using namespace std;

// Function to find the maximum element in an array


int findMax(int arr[], int size) {
int max = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}

// Function to find the minimum element in an array


int findMin(int arr[], int size) {
int min = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}

// Function to display the array


void displayArray(int arr[], int size) {
cout << "Array elements: ";
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}

// Function to display the statistics of the array


void displayStatistics(int arr[], int size) {
int max = findMax(arr, size);
int min = findMin(arr, size);
cout << "Maximum element in the array is: " << max << endl;
cout << "Minimum element in the array is: " << min << endl;
}

int main() {
int arr[] = {10, 20, 30, 40, 50};
int size = sizeof(arr) / sizeof(arr[0]);

displayArray(arr, size);
displayStatistics(arr, size);

return 0;
}

You might also like