Sunday, January 8, 2023

C Programming. Palindrome function.

Palindrome Function.

Function to check if a string is Palindrome or not.


#include<stdio.h>

void isPalindrome(char str[]);
   

int main(){
    char str[100];
    printf("Enter a string : ");
    gets(str);
    isPalindrome(str);
    return 0;
}

void isPalindrome(char str[]){
    char rev[100];
   
    int c=0,i,id=0;
    for (i=0; str[i]!='\0'; i++){
        c++;
    }
    for (i=c-1; i>=0; i--){
        rev[id]=str[i];
        id++;
    }
    c=0;
    for (i=0; str[i]!='\0'; i++){
        if (rev[i]==str[i]){
            c++;
        }
    }
    if (c==i){
        printf("Palindrom");
    }
    else{
        printf("Not Palindrom");
    }

}

No comments:

Post a Comment

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...