forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tarunsinghofficial#736 from sidverr/main
Palindrome
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Siddharth Verma | ||
Photo - https://d1kkg0o175tdyf.cloudfront.net/large/s_411d1093b98c-2019-09-26-20-30-25-000640.jpg | ||
Location : India | ||
Github: https://github.com/sidverr |