Answers for "code print palindrome"

C
1

check if the c code is a palindrome

#include <stdio.h>
#include <string.h>

int main(){
    char string1[20];
    int i, length;
    int flag = 0;
    
    printf("Enter a string:");
    scanf("%s", string1);
    
    length = strlen(string1);
    
    for(i=0;i < length ;i++){
        if(string1[i] != string1[length-i-1]){
            flag = 1;
            break;
   }
}
    
    if (flag) {
        printf("%s is not a palindrome", string1);
    }    
    else {
        printf("%s is a palindrome", string1);
    }
    return 0;
}
Posted by: Guest on January-18-2022
1

minimum characters to make string palindrome

string s;
    int len=0,i=1;
    cin>>s;
    int n=s.size();
    vector<int> LPS(n);
    LPS[0]=0;
    while(i<n)
    {
        if(s[i]==s[len]) LPS[i++]=++len;
        else
        {
            if(len==0) LPS[i++]=0;
            else len=LPS[len-1];
        }
    }
Posted by: Guest on December-21-2021

Code answers related to "C"

Browse Popular Code Answers by Language