Palindrome

Wrong OUTPUT ,HELP !
//to check whether the string is palindrome or not
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main ()
{
clrscr();
char s[50];
int i,l,j,flag=0;
cout<<"Enter string :";
gets(s);
l=strlen(s);
for(i=0,j=l-1;i<l,j<1;i++,j--)
{
if(s[i]==s[j])
flag=1;
}
if(flag==1)
cout<<"\nThe string is a palindrome";
else
cout<<"\nthe string is not a palindrome";
getch();
}
Checking palindrome using strings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]){
	string s1;
	string s1_rev;

	cin >> s1;
	
	s1_rev = s1;
	reverse(s1_rev.begin(), s1_rev.end());
	
	if (s1 == s1_rev)
		cout << "Palindrome." << endl;
	else
		cout << "Not palindrome." << endl;

	return 0;
}


Hope I could help,
~ Raul ~
Last edited on
Topic archived. No new replies allowed.