diff --git a/algorithms/C/README.md b/algorithms/C/README.md index afbc76de..fe4adb7b 100644 --- a/algorithms/C/README.md +++ b/algorithms/C/README.md @@ -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) diff --git a/algorithms/C/maths/palindrome.c b/algorithms/C/maths/palindrome.c new file mode 100644 index 00000000..b3ee3a07 --- /dev/null +++ b/algorithms/C/maths/palindrome.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 //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). diff --git a/algorithms/CPlusPlus/Maths/prime-number.cpp b/algorithms/CPlusPlus/Maths/prime-number.cpp index c50e8604..fec15c2c 100644 --- a/algorithms/CPlusPlus/Maths/prime-number.cpp +++ b/algorithms/CPlusPlus/Maths/prime-number.cpp @@ -31,4 +31,4 @@ int main() { //main function // 4 || Non-Prime // 5 || Prime -// time complexity of this program is O(n). +// time complexity of this program is O(n). \ No newline at end of file diff --git a/algorithms/CPlusPlus/README.md b/algorithms/CPlusPlus/README.md index 70cc84ee..47312f12 100644 --- a/algorithms/CPlusPlus/README.md +++ b/algorithms/CPlusPlus/README.md @@ -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)