Computer Science, asked by swethachowdary845, 9 months ago

A special school is run by an NGO for kids with Dyslexia. We all know these children will start writing the letters backward or in reverse. Once special care is taken to correct this issue and once they are introduced to words, they will start writing the words in the proper format. The teachers do not want to discourage the children at the start itself and they have decided to mark the words written in reverse also as correct. Can you please help the teacher in correcting the answer sheets by writing a C++ program? Write a C++ program to check whether the second word is the reverse of the first word. Do not use strrev() function.

Answers

Answered by kavetisrinija99
10

Answer:

#include<iostream>

#include<string.h>

#include<stdlib.h>

using namespace std;

void strrev(char *str)

{

 int i=0,j=0;

 while(str[j+1]) j++;

 while(i < j)

 {

   char temp=str[i];

   str[i]=str[j];

   str[j]=temp;

   i++;

   j--;

 }

}

int main()

{

 char str1[50],str2[50];

 gets(str1);

 gets(str2);

 strrev(str1);

 if(strcmp(str2,str1)==0)

   cout<<"It is correct";

 else

   cout<<"It is wrong";

   return 0;

}

Explanation:

ALL TEST CASES ARE PASSED

Answered by anagasatyasri710
11

Answer:

#include<iostream>

#include<string.h>

#include<stdlib.h>

using namespace std;

void strrrev(char * str)  

{

int j = 0, i = 0;

while(str[j+1]) j++;

while(i < j)  

{

char temp = str[i];

str[i] = str[j];

str[j] = temp;

i++;

j--;

}

}

int main()

{

char str1[50],str2[50];

gets(str1);

gets(str2);

strrrev(str1);

if(strcmp(str2,str1)==0)

cout<<"It is correct";

else

cout<<"It is wrong";

return 0;

}

Explanation:

Similar questions