-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIsPalindrome_3Recursion.cpp
More file actions
60 lines (46 loc) · 1.12 KB
/
IsPalindrome_3Recursion.cpp
File metadata and controls
60 lines (46 loc) · 1.12 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
/*
Is Palindrome_3
Take as input a number N and store that in an array.
Write a recursive function that tests if the array is palindrome or not
and returns a boolean value and print that value also.
*/
#include<iostream>
using namespace std;
int main()
{
int N, A[20];
bool x, IsPalindrome(int [], int, int);
cout<<"Enter array size : ";
cin>>N;
if(N>0)
{
cout<<"\nEnter the number :\n";
for(int i=0; i<N; ++i)
cin>>A[i];
int j=N-1;
x=IsPalindrome(A,N,j);
if(x==true)
cout<<"\nResult ( '1' means True and '0' means False ) : "<<x<<endl;
else
cout<<"\nResult ( '1' means True and '0' means False ) : "<<x<<endl;
}
else
cout<<"\nArray size should be atleast greater than 1!!!\n";
return 0;
}
int i=0;
bool IsPalindrome(int A[], int N, int j)
{
if(i<N/2)
{
if(A[i]!=A[j])
return false;
else
{
++i;
--j;
IsPalindrome(A,N,j);
}
}
return true;
}