Monday, July 31, 2017

Check if a string is palindrome or not in C ?

#include<stdio.h>
#include<string.h>
void main()
{
    char word[50];
    int i,j,l,c=0;
    printf("Enter a word : ");
    gets(word);
    l=strlen(word);
    for(i=0,j=l-1;i<l/2;i++,j--)
    {
        if(word[i]-word[j]>0)
        {
            c=1;
            break;
        }
    }
    if(c==0)
    {
        printf("Palindrome");
    }
    else
    {
        printf("Not palindrome");
    }
    getch();
}

Related Posts:

  • Find fibonacci series in C#include<stdio.h> void fibonacci(int); void main() {     int n,first=0,second=1;     printf("Enter the number of fibonacci series to be printed : ");     scanf("%d",&n);     p… Read More
  • Find highest paid employee in C#include<stdio.h> struct emp {     char name[50];     int salary; }; void main() {     int n,i,sum=0,avg;     struct emp e[20],ls,hs;     printf("Enter the number of emp… Read More
  • Find triangular no. in C#include<stdio.h> void main() {     int n1,n2,i,t;     printf("Enter two numbers : ");     scanf("%d%d",&n1,&n2);     for(i=1;i<=n2;i++)     {     &… Read More
  • Operations on complex numbers in C#include<stdio.h> struct cmplx {     float real;     float img; }; struct cmplx add(struct cmplx x, struct cmplx y) {     struct cmplx z;     z.real = x.real + y.real;   &nbs… Read More
  • Find no. of vowels in a string in C #include<stdio.h> void strcount(char []); void main() {   char str[50];   char c;   while(1)   {     printf("enter string\n");     //gets(str);     scanf("%s",str); &nb… Read More

0 comments:

Post a Comment