-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path56.cpp
More file actions
31 lines (25 loc) · 845 Bytes
/
56.cpp
File metadata and controls
31 lines (25 loc) · 845 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
#include <iostream>
bool isSorted(int arr[], int size) {
for (int i = 1; i < size; ++i) {
if (arr[i] < arr[i - 1]) {
return false; // If any element is less than the previous, the array is not sorted
}
}
return true; // If the loop completes without finding any out-of-order elements, the array is sorted.
}
int main() {
int size;
std::cout << "Enter the size of the array: ";
std::cin >> size;
int arr[size];
std::cout << "Enter the elements of the array:" << std::endl;
for (int i = 0; i < size; ++i) {
std::cin >> arr[i];
}
if (isSorted(arr, size)) {
std::cout << "The array is sorted in ascending order." << std::endl;
} else {
std::cout << "The array is not sorted in ascending order." << std::endl;
}
return 0;
}