Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- using namespace std;
- bool check(char word[], int index) /// function to check if palindrome or not
- {
- int len = strlen(word) - (index + 1);
- if (word[index] == word[len])
- {
- if (index + 1 == len || index == len){
- return 1; ///if string is a palindrome
- }
- check(word, index + 1); /// function calling itself
- }
- else{
- return 0; /// if not a palindrome
- }
- }
- int main() //main function
- {
- ///declare the variables
- string string;
- bool b;
- char word[100];
- cout <<"Welcome!" << endl;
- cout<<"Please enter a word: ";
- getline(cin , string); /// user inputs desired string to check
- strcpy(word, string.c_str()); /// fill array up by reading string into it
- b = check(word, 0); ///function call to return a false or true return statement
- if(b){
- cout<< string << " is a palindrome!"; ///if a palindrome
- }else{
- cout<<string <<" is not a palindrome!"; /// if not a palindrome
- }
- cout << "\nThank you for using this program";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement