diff --git a/palindromic_string/palindromic_string.c b/palindromic_string/palindromic_string.c new file mode 100644 index 0000000000..1984bbde4a --- /dev/null +++ b/palindromic_string/palindromic_string.c @@ -0,0 +1,54 @@ +/* +C Programme to check palindromic string. +A Palindromic String is a sequence of characters which is +the same when read both forward and backward. +*/ + +#include +#include + +// Driver function +int main() +{ + char string1[20]; + int i, length; + bool flag = false; + + printf("Enter a string: "); + scanf("%s", string1); + + length = strlen(string1); + + for(i = 0; i < length/2; i++) + { + if(string1[i] != string1[length - i - 1]) + { + flag = true; + break; + } + } + + if (flag) + { + printf("%s is not a palindrome", string1); + } + else + { + printf("%s is a palindrome", string1); + } + return 0; +} + +/* +Input: +radar + +Output: +radar is a palindrome + +Input: +Enter a string: india + +Output: +india is not a palindrome +*/ diff --git a/palindromic_string/palindromic_string.cpp b/palindromic_string/palindromic_string.cpp new file mode 100644 index 0000000000..11720adbeb --- /dev/null +++ b/palindromic_string/palindromic_string.cpp @@ -0,0 +1,55 @@ +/* +C++ Programme to check palindromic string. +A Palindromic String is a sequence of characters which is +the same when read both forward and backward. +*/ + +#include +#include +using namespace std; + +// Driver function +int main() +{ + char string1[20]; + int i, length; + bool flag = false; + + cout << "Enter a string: "; + cin >> string1; + + length = strlen(string1); + + for(i = 0; i < length/2; i++) + { + if(string1[i] != string1[length - i - 1]) + { + flag = true; + break; + } + } + + if (flag) + { + cout << string1 << " is not a palindrome" << endl; + } + else + { + cout << string1 << " is a palindrome" << endl; + } + + return 0; +} + +/*Input: +radar + +Output: +radar is a palindrome + +Input: +Enter a string: india + +Output: +india is not a palindrome +*/ \ No newline at end of file