Friday, 21 April 2017

Program to check whether string is palindrome or not without using library function

Program to check whether string is palindrome or not without using library function


#include<stdio.h>

 void main()
{
            char s[20];
            int i=0, len, flag = 0;
            printf("\nEnter s1: ");
            gets(s);

            /*To find the length of the string*/
            while(s[i]!='\0')
            {
                        i++;
            }

            len = i;

            for(i=0; i<len/2; i++)
            {
                        if(s[i] != s[len-i-1])
                        {
                                    flag = 1;
                                    break;
                        }
            }

            if(flag == 0)
                        printf("\nString is palindrome.");
            else
                        printf("\nString is not palindrome.");
}


Output:
Enter s1: abcba
Strings is palindrome.

1 comment:

  1. VTU results 2018 will be released soon, check here for results. https://vturesults.xyz/vtu-results

    ReplyDelete