A special school is run by an NGO for kids with Dyslexia. As 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 reverse. The teachers do not want to discourage the children at the start itself and they have decided to mark the works 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.
Input Format:
Input consists of 2 strings. Assume that the maximum length of the string is 50.

Sample Input:
Enter the actual word
Excellent
Enter the word the student has typed
tnellecxE
Sample Output:
It is correct

Sample Input:
Enter the actual word
Excellent
Enter the word the student has typed
tneilecxE
Sample Output:
It is wrong

Program Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
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];
    //string str1,str2;
    //int c;
    printf("Enter the actual word");
    gets(str1);
    printf("\nEnter the word the student has typed");
    gets(str2);
    strrrev(str1);
    if(strcmp(str2,str1)==0)
    //if(c==0)
    printf("\nIt is correct");
    else
    printf("\nIt is wrong");
    return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: