forked from Haresh1204/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome.cpp
40 lines (35 loc) · 809 Bytes
/
Palindrome.cpp
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
#include<stdio.h>
// declaring the recursive function
int isPal(int );
/*
global declaration to use the same value
in both the functions
*/
int n;
int main()
{
printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
int palindrome;
printf("\n\nEnter a number to check for Palindrome: ");
scanf("%d", &n);
palindrome = isPal(n);
if(palindrome == 1)
printf("\n\n\n%d is palindrome\n\n", n);
else
printf("\n\n\n%d is not palindrome\n\n", n);
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}
int isPal(int aj)
{
static int sum = 0;
if(aj != 0)
{
sum = sum *10 + aj%10;
isPal(aj/10); // recursive call same as while(n!=0) using loop
}
else if(sum == n)
return 1;
else
return 0;
}