Skip to content

Commit

Permalink
max and min element of array
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishak798 authored Mar 6, 2024
1 parent 856980f commit 68f9bb3
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Array_Questions/findmaxandminarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**Write a program in C to find the maximum and minimum elements in an array.
Test Data :
Input the number of elements to be stored in the array :3
Input 3 elements in the array :
element - 0 : 45
element - 1 : 25
element - 2 : 21
Expected Output :
Maximum element is : 45
Minimum element is : 21**/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "enter size of array: ";
cin >> n;
int arr[n];
cout << endl;
for (int i = 0; i < n; i++)
{
cout << "Enter element " << i << " :";
cin >> arr[i];
cout << endl;
}
int max = arr[0];
int min = arr[0];
for (int i = 0; i < n; i++)
{
if (arr[i] < min)
{
min = arr[i];
}
if (arr[i] > max)
{
max = arr[i];
}
}
cout << "Minimum Element of array is " << min << endl;
cout << "Maximum Element of array is " << max;
return 0;
}
/*output
enter size of array: 4
Enter element 0 :8
Enter element 1 :9
Enter element 2 :0
Enter element 3 :1
Minimum Element of array is 0
Maximum Element of array is 9
*/

0 comments on commit 68f9bb3

Please sign in to comment.