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
parent
213aa584fa
commit
779a37f83a
|
@ -22,6 +22,9 @@
|
||||||
- [Doubly Linked List](linked-lists/doubly-linked-list.c)
|
- [Doubly Linked List](linked-lists/doubly-linked-list.c)
|
||||||
- [Glued-Linked-List](linked-lists/gl-threads.c)
|
- [Glued-Linked-List](linked-lists/gl-threads.c)
|
||||||
|
|
||||||
|
## Maths
|
||||||
|
- [Palindrome Number](Maths/palindrome.c)
|
||||||
|
|
||||||
## Queues
|
## Queues
|
||||||
- [Double Ended Queue using array](queues/double-ended-queue-using-array.c)
|
- [Double Ended Queue using array](queues/double-ended-queue-using-array.c)
|
||||||
|
|
||||||
|
|
|
@ -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).
|
|
@ -132,7 +132,6 @@
|
||||||
10. [Factorial of a number](Maths/factorial.cpp)
|
10. [Factorial of a number](Maths/factorial.cpp)
|
||||||
11. [Prime-number](Maths/prime-number.cpp)
|
11. [Prime-number](Maths/prime-number.cpp)
|
||||||
|
|
||||||
|
|
||||||
# Recursion
|
# Recursion
|
||||||
|
|
||||||
1. [Tower of Hanoi](Recursion/towerofHanoi.cpp)
|
1. [Tower of Hanoi](Recursion/towerofHanoi.cpp)
|
||||||
|
|
Loading…
Reference in New Issue