-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsa.cpp
More file actions
67 lines (54 loc) · 1.14 KB
/
Copy pathdsa.cpp
File metadata and controls
67 lines (54 loc) · 1.14 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#Palindrome
/* #include <iostream>
using namespace std;
int main() {
int x;
cout << "Enter a number: ";
cin >> x;
if (x < 0) {
cout << "Negative numbers cannot be palindrome.";
return 0;
}
int a = x;
int rev = 0;
int digit;
while (x > 0) {
digit = x % 10;
rev = rev * 10 + digit;
x /= 10;
}
if (a == rev)
cout << "Palindrome";
else
cout << "Not Palindrome";
return 0;
} */
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter size of array: ";
cin >> n;
int arr[n];
cout << "Enter elements: ";
for (int i = 0; i < n; i++)
cin >> arr[i];
// Sorting
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (arr[i] > arr[j])
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
cout << "Sorted Array: ";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}