diff --git a/Palindrome/palindrome_no.c b/Palindrome/palindrome_no.c new file mode 100644 index 0000000000..34d520cd30 --- /dev/null +++ b/Palindrome/palindrome_no.c @@ -0,0 +1,41 @@ +/* +This program checks whether the enterd number is palindrome or not and generates output according to input provided. +*/ + +#include +int main() +{ + int n,rem,temp,rev = 0; + printf("\nEnter a number: "); + scanf("%d",&n); + temp = n; + while(temp != 0) + { + rem = temp % 10; + temp = temp / 10; + rev = (rev * 10) + rem; + } + if(rev != n) + { + printf("\nEntered number is not palindrome.\n"); + } + else + { + printf("\nEntered number is palindrome.\n"); + } + return 0; +} + + + +/* + INPUT: + n=12456 + OUTPUT: + Entered no. is not palindrome. + + INPUT: + n=12821 + OUTPUT: + Entered no. is palindrome. +*/ diff --git a/Palindrome/palindrome_no.cpp b/Palindrome/palindrome_no.cpp new file mode 100644 index 0000000000..4198b55b24 --- /dev/null +++ b/Palindrome/palindrome_no.cpp @@ -0,0 +1,43 @@ +/* +This program checks whether the enterd number is palindrome or not and generates output according to input provided. +*/ + + +#include +using namespace std; +int main() +{ + int n,rem,rev = 0; + cout << "Enter a number: "; + cin >> n; + int temp = n; + while(temp != 0) + { + rem = temp % 10; + temp = temp / 10; + rev = (rev * 10) + rem; + } + if(rev != n) + { + cout << "Entered number is not palindrome." << endl; + } + else + { + cout << "Entered number is palindrome." << endl; + } + return 0; +} + + + +/* + INPUT: + n=12456 + OUTPUT: + Entered no. is not palindrome. + + INPUT: + n=12821 + OUTPUT: + Entered no. is palindrome. +*/ diff --git a/Palindrome/palindrome_string.cpp b/Palindrome/palindrome_string.cpp new file mode 100644 index 0000000000..a34e9561fc --- /dev/null +++ b/Palindrome/palindrome_string.cpp @@ -0,0 +1,51 @@ +/* +This program checks whether the enterd string is palindrome or not and generates output according to input provided. +*/ + +#include +#include // to use swap() +using namespace std; + +void string_palindrome(string s) +{ + string reverse = s; + int n = s.length(); + for(int i=0;i> str; + string_palindrome(str); + return 0; +} + + + +/* +INPUT: + Enter a string: abhnch + +OUTPUT: + abhnch is not Palindrome. + +_______________________________________ + +INPUT: + Enter a string: adbcbda + +OUTPUT: + adbcbda is Palindrome. +*/