Palindrome String

Given a String S, Check Whether The Given String S is Palindrome or Not. If The Given String is Palindrome Then Print "Palindrome" (Without Quotes) else Print "Not Palindrome" (Without Quotes)

Example:

Input:  s = "madam"
Output: Palindrome

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void palindromeString(string s)
{
    int n = s.size();
    int flag = 0;
    for (int i = 0i < n / 2i++)
    {
        if (s[i] != s[n - i - 1])
        {
            flag = 1;
            break;
        }
    }
    if (flag == 0)
        cout << "Palindrome\n";
    else
        cout << "Not Palindrome\n";
}
int main()
{
    string s = "madam";

    palindromeString(s);

    return 0;
}


No comments:

Post a Comment