/*
Program that will take an array of Characters as parameters and checks whether it is a
Palindrome or not using function.
*/
#include<iostream>
using namespace std;
bool isPalindrome(char[]);
int main()
{
char str[50];
cout << "Enter string?\t";
cin >> str;
//Displays result
if (!isPalindrome(str)) cout << "Entered string is Palin-Drome";
else
cout << "Entered string is not Palin-Drome";
cout << endl;
return 0;
}
bool isPalindrome(char str[])
{
int l;
//For calculating entered string length
for (l = 0; str[l] != '\0'; l++);
//for checking wether string is Palindrome or not
for (int i = l - 1, j = 0; j < l / 2; i--, j++)
if (str[j] != str[i])
return 1;
return 0;
}
OUTPUT
No comments:
Post a Comment