Answer to Question #50071 in C++ for danaa

Question #50071
Write a program that given two character strings from the user:
 Checks these two character strings to see if one string is the reverse of the other.
 If the strings are reverse, display: “Reverse Strings Found”, otherwise display: “Reverse Strings Not Found”.
 Create a function to perform this task.
Expert's answer
#include <iostream>
#include <conio.h> // for getch(); _getch()
using namespace std;

bool AreReverse(char* leftStr,char* rightStr);
void main()
char* s1 = "Lal";
char* s2 = "laL";

if (AreRevers(s1, s2))
cout <<"Reverse Strings Found" << endl;
cout <<"Reverse Strings Not Found" << endl;
cout << "Press any key tocontinue...";
getch(); // or _getch() if this codedoesn't work
bool AreReverse(char* leftStr, char* rightStr)
int length = strlen(leftStr);
if (length != strlen(rightStr)) // ifstrings lengths aren't equal they won't be reverse by definition
return false;
for (int i = 0, j = length - 1; i <length; i++, j--)
if (leftStr[i] !=rightStr[j]) // if beginning symbols of the first string aren't equal to last
symbols of the second string
return false;
return true;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be the first!

Leave a comment

Ask Your question

New on Blog