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


Please Help Members By Posting Answers For Below Questions

what value is returned to operating system after program execution?

1611


What is the advantage of c?

619


a direct address that identifies a location by means of its displacement from a base address or segment a) absolute address b) relative address c) relative mode d) absolute mode

667


What is advantage of pointer in c?

707


When should the volatile modifier be used?

695






What is a pointer in c?

695


I came across some code that puts a (void) cast before each call to printf. Why?

689


What is the value of c?

585


void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply

2235


What the different types of arrays in c?

622


Why static variable is used in c?

574


Can we declare a function inside a function in c?

606


What is c programing language?

629


a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

667


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

627