Friday, February 23, 2024

5. Write a function that checks whether a given string is Palindrome or not. Use this function to find whether the string entered by user is Palindrome or not.

 #include <stdio.h>

#include <string.h>



void Lower_case(char str[]) {

    int i = 0;

    while (str[i] != '\0') {

        if (str[i] > 64 && str[i] < 91) 

            str[i] += 32; 


        i++; 

    } 


void CheckPalindrome(char str[]) 


    

    int left = 0; 

    int right = strlen(str) - 1; 


    while (right > left) 

    {

        if (str[left++] != str[right--]) {

            printf("The String %s is not a palindrome", str);

            return;

        }

    }

    printf("The String %s is palindrome", str);

}

int main() 

{

    char str1[50];

    printf("enter a string");

    gets(str1);

    Lower_case(str1);

    CheckPalindrome(str1);

    

    return 0;

}

No comments:

Post a Comment