+ 1

i am trying to find out weather the entered string is palindrome or not ,but this code isn't giving the correct output.

#include <iostream> using namespace std; string isPalindrome(string s, int n) { int i=0; for(;i<n;i++) { if(s[i]==s[n-i-1]) continue; else return "No"; } return "Yes"; } int main() { //code int n; // size of the string cin >>n; string s; // cin >> s; cout << isPalindrome(s,n) << endl; return 0; }

23rd May 2020, 12:12 PM
SHIVANSHU BAJPAI
SHIVANSHU BAJPAI - avatar
2 Antworten
+ 1
Inputs: 5 12721 Works fine Edit: else{ return "No"; break; }
23rd May 2020, 12:25 PM
Abhay
Abhay - avatar
0
Try to enter a non palindrome string
23rd May 2020, 12:36 PM
SHIVANSHU BAJPAI
SHIVANSHU BAJPAI - avatar