Answer to Question #144666 in C for Unknown

Question #144666
Enter two strings and check whether one string is the reverse of other or not. For example, consider the strings “vikas” and “sakiv”, you can notice that one string is the reverse of other.
1
Expert's answer
2020-11-16T13:34:51-0500
#include <cstdio>
#include <cstring>

int main() {
    char s1[100], s2[100];
    int i, len1, len2, reverse_equal = 1;
    printf("Enter first string: \n");
    scanf("%s", s1);
    printf("Enter second string: \n");
    scanf("%s", s2);
    len1 = strlen(s1);
    len2 = strlen(s2);
    if (len1 == len2) {
        for (i = 0; i < len1; ++i) {
            if (s1[i] != s2[len2-i-1]) {
                reverse_equal = 0;
            }
        }
    } else {
        reverse_equal = 0;
    }

    if (reverse_equal) {
        printf("one string is the reverse of other\n");
    } else {
        printf("one string is not the reverse of other\n");
    }
    return 0;
}



OUTPUT:


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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS