-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
856980f
commit 68f9bb3
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |