-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIsPalindrome.cpp
More file actions
42 lines (30 loc) · 800 Bytes
/
IsPalindrome.cpp
File metadata and controls
42 lines (30 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Take as input a string.
Write a function that returns true if the string is palindrome
and false otherwise.
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
char str[20];
int len=0, check, isPalin(char [],int);
cout<<"Enter a string :"<<endl;
gets(str);
for(len=0;str[len]!='\0';len++); //to determine length of the string
check=isPalin(str,len); //function call
if(check!=-1)
cout<<"\nTRUE!!!\n";
else
cout<<"\nFALSE\n";
return 0;
}
int isPalin(char str[], int len)
{
int x,i;
for(i=0,x=len-1;(str[i]!='\0'),x>=0;i++,x--)
if(str[i]!=str[x]) //returns -1 if they are not equal
return -1;
return 0;
}