Write a C, C++ program to check whether string is palindrome or not.
In this program we are using in-built string functions.
Program to check whether string is palindrome or not without using any in-built library function.
Program to check whether number is palindrome or not.
Programming questions on strings.
Let's first understand what is Palindrome.
Palindrome is a word, phrase, or sequence that reads the same backwards as forwards.
For example - Nitin, Madam etc.
If you reverse word Nitin it's still remains the same.
How do we check whether a string is palindrome or not ?
We have discussed, what is palindrome so how do we check whether input string is palindrome or not.
There are multiple approaches, let's discuss it.
METHOD 1 Take input string then reverse the input string if both strings are same then it's a palindrome.
METHOD 2 Traverse string from both the ends and compare, if both the indexes are equal then it's a palindrome.
Implementation of method 2 to check whether string is palindrome or not.
In this program we are using in-built string functions.
Program to check whether string is palindrome or not without using any in-built library function.
Program to check whether number is palindrome or not.
Programming questions on strings.
Let's first understand what is Palindrome.
Palindrome is a word, phrase, or sequence that reads the same backwards as forwards.
For example - Nitin, Madam etc.
If you reverse word Nitin it's still remains the same.
How do we check whether a string is palindrome or not ?
We have discussed, what is palindrome so how do we check whether input string is palindrome or not.
There are multiple approaches, let's discuss it.
METHOD 1 Take input string then reverse the input string if both strings are same then it's a palindrome.
METHOD 2 Traverse string from both the ends and compare, if both the indexes are equal then it's a palindrome.
Implementation of method 2 to check whether string is palindrome or not.
Program to Check Whether a String is Palindrome in C
#include<stdio.h> #include<string.h> Void main() { /* Declare String. String is a series of characters. */ char str1[150], str2[150]; /* Take input string. */ printf("Enter any string"); gets(str1); /* Copy the value of str1 into str2. */ strcpy(str2,str1); /* Reverse string 2. */ strrev(str2); if( strcmp(str1,str2) == 0 ) printf("Palindrome"); else printf("Not a pailndrome.\n"); }
Program to check whether string is palindrom in C++
//include
No comments:
Post a Comment