In these days kids are introduced to computers at a very early age and in some schools, the dictation test is conducted using computers. The teachers found it a bit difficult to evaluate these tests and they requested the school management to lessen their burden by automating this task. The 12th class students are learning C programming and they took up the task of automating the dictation evaluation. The students have not been introduced to string functions yet. Can you please help them out?
Write a C program to compare 2 strings.
Input Format:
Input consists of 2 strings. Assume that the maximum length of the string is 50 and it contains only alphabets.
Output Format:
Refer sample input and output for formatting specifications.Sample Input and Output 1:
Enter the word
Excellent
Enter the word the student has typed
Excellent
It is correct
Sample Input and Output 2:
Enter the word
Excellent
Enter the word the student has typed
Excelent
It is wrong
Program Code:
#include<stdio.h>
int main()
{
char str1[50];char str2[50];
int i=0; int flag=0;
printf("Enter the word");
scanf("%s",str1);
printf("\nEnter the word the student has typed");
scanf("%s",str2);
while(str1[i]!='\0' && str2[i]!='\0')
{
if(str1[i]!=str2[i])
{
flag=1;
break;
}
i++;
}
if(flag==0)
printf("\nIt is correct");
else
printf("\nIt is wrong");
//printf("\nThe number of letters in the name is %d",l);
return 0;
}
Post A Comment:
0 comments: