Write a program to compare two strings without using the
strcmp() function
Answer Posted / navy
#include<stdio.h>
#include<conio.h>
void main()
{
char s1[20];
int i, j, len=0, flag=0;
printf("\nEnter any string: ");
gets(s1);
for (i=0; s1[i]!='\0'; i++)
len++;
i = 0;
j = len-1;
while (i < len)
{
if (s1[i] != s1[j])
{
flag = 1;
break;
}
i++;
j--;
}
if (flag == 0)
printf("\nString is palindrome");
else
printf("\nString is not palindrome");
getch();
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Explain how can I read and write comma-delimited text?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
What are compound statements?
What happens if you free a pointer twice?
What is #define?
How can I automatically locate a programs configuration files in the same directory as the executable?
Is a house a mass structure?
Multiply an Integer Number by 2 Without Using Multiplication Operator
What is file in c preprocessor?
Explain what are the __date__ and __time__ preprocessor commands?
What is c basic?
How are portions of a program disabled in demo versions?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
Can we use visual studio for c?
Why do we use header files in c?