-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_array_palindrome.cpp
More file actions
38 lines (35 loc) · 864 Bytes
/
is_array_palindrome.cpp
File metadata and controls
38 lines (35 loc) · 864 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
32
33
34
35
36
37
38
// Problem: Check if an array is palinodrome or not.
// Example: Input: arr[] = {3, 6, 0, 6, 3}
// Output: Palindrome
// Input: arr[] = {1, 2, 3, 4, 5}
// Output: Not Palindrome
#include <iostream>
using namespace std;
int palinoArray (int arr[], int size) {
int flag = 0;
for (int i=0; i<=size/2 && size != 0; i++) {
if (arr[i] != arr[size-i-1]) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << "Not Palinodrome" << endl;
}
else {
cout << "Is Palinodrome" << endl;
}
return 0;
}
int main() {
int size, arr[100];
cout << "Enter size of array: ";
cin >> size;
for ( int i=0; i<size; i++) {
cout << " Value at index " << i+1 << " : ";
cin >> arr[i];
}
cout << endl;
palinoArray(arr, size);
return 0;
}