adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to check a given string is palindrome or not Using recursive function

Program in C++ to check a given string is palindrome or not Using recursive function


C Program
#include<stdio.h>
#include<string.h>
 void palindrome(char *str){
    int len, i;
    len = strlen(str);
    for(i = 0; i < len / 2; i++){
        if(str[i] != str[len - 1 - i]){
            printf("%s is not palindrome string.",str);
            return;
        }
    }
    printf("%s is palindrome string.",str);
 }
 int main(){
    char *str;
    str = malloc(50); // type casting is optional
    printf("Enter a string :- ");
    scanf("%s",str);
    palindrome(str);
    return 0;
 }
C++ Program
#include<iostream>
#include<string.h>
#include<stdlib.h>
 using namespace std;
 void palindrome(char *str){
    int len, i;
    len = strlen(str);
    for(i = 0; i < len / 2; i++)
        if(str[i] != str[len - 1 - i]){
            cout<<str<<" is not palindrome string.";
            return;
        }
    cout<<str<<" is palindrome string.";
 }
 int main(){
    char *str;
    str =(char*)malloc(50);
    cout<<"Enter a string :- ";
    cin>>str;
    palindrome(str);
    return 0;
 }
Output :-







Related Programs


Recursive function




Post a Comment

0 Comments