-
Notifications
You must be signed in to change notification settings - Fork 3
/
IsReverse.cpp
45 lines (33 loc) · 855 Bytes
/
IsReverse.cpp
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
43
44
45
/*
Is Reverse?
Take as input two strings.
Write a function which tests if string-2 is reverse of string-1 or not and
returns a Boolean value.
Print the vaue returned.
*/
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char first[20], second[20];
bool x, checkReverse(char [], char []);
cout<<"Enter first string :\n";
gets(first);
cout<<"\n\nEnter second string :\n";
gets(second);
x=checkReverse(first,second);
if(x==1)
cout<<"\nResult : TRUE\n";
else
cout<<"\nResult : FALSE\n";
return 0;
}
bool checkReverse(char first[], char second[])
{
int len2=strlen(second);
for(int i=0, j=len2-1; ((first[i]!='\0'),j>=0); i++, j--)
if(first[i]!=second[j])
return false;
return true;
}