20_10

Write a C code to check whether a given string is palindrome or not.

Source code:

 /*A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, e.g. madam 123321 etc. Write a C code to check whether a given string is palindrome or not. */

#include <stdio.h>

#include <string.h>

int main(){

    char string[20];

    int flag = 0;

    printf("Enter a string:");

    //Read a String

    scanf("%s", string);

int i, length; 

length = strlen(string);

  for(i=0; i < length ; i++){

        if(string[i] != string[length-i-1]){

            flag = 1;

            break;

    }

}

  if (flag) {

        printf("The given string %s is not palindrome", string);

    }

    else {

        printf("The given string %s is palindrome", string);

    }

    return 0;

}

Output:

C code to check whether a given string is palindrome or not


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...