chore(C): add palindrome program (#504)

Co-authored-by: Rahul Rajeev Pillai <66192267+Ashborn-SM@users.noreply.github.com>
Co-authored-by: Ming Tsai <37890026+ming-tsai@users.noreply.github.com>
pull/509/head^2
kumarsyadav2 2021-10-07 18:40:14 +05:30 committed by GitHub
parent 213aa584fa
commit 779a37f83a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 2 deletions

View File

@ -22,6 +22,9 @@
- [Doubly Linked List](linked-lists/doubly-linked-list.c)
- [Glued-Linked-List](linked-lists/gl-threads.c)
## Maths
- [Palindrome Number](Maths/palindrome.c)
## Queues
- [Double Ended Queue using array](queues/double-ended-queue-using-array.c)

View File

@ -0,0 +1,34 @@
// This program is used to calculate palindrome number in C
// a palindrome number is a number which is same on reversing that number
#include <stdio.h> //header
int main () //main function
{
int num, rev = 0, r, s; //define variables
printf (" enter the number: ");
scanf ("%d", &num); // taking input
s = num; //assigning num to s
while (s > 0)
{ // loop starts
r = s % 10;
rev = rev * 10 + r; // calculating reverse
s = s / 10;
}
if (num == rev)
{ // checking if condition
printf ("Palindrome"); //printing if number is palindrome
}
else
{
printf ("Non-palindrome"); //printing if number is not palindrome
}
return 0; //returning main function
}
// sample input || sample output
// 121 || Palindrome
// 438 || Non-palindrome
// 787 || Palindrome
// 975 || Non-Palindrome
// This program is having time complexity of O(N).

View File

@ -132,7 +132,6 @@
10. [Factorial of a number](Maths/factorial.cpp)
11. [Prime-number](Maths/prime-number.cpp)
# Recursion
1. [Tower of Hanoi](Recursion/towerofHanoi.cpp)