Tuesday, October 18, 2022

BCA and B.Sc Programs - Programming in C Lab - Bharathiar University - Practical Program 6 - C Program to check whether the given string is palindrome or not using Pointers



Write a C Program to check whether the given string is palindrome or not using Pointers



 


Source code
String palindrome using pointers in c

#include<stdio.h>

#include<string.h>

void main()

{

    char str[1000];

    char *ptr1, *ptr2;

    printf("Enter the String:");

    scanf("%s",str);

    ptr1=str;

    while(*ptr1!='\0')

    {

        ++ptr1;

    }

    --ptr1;

    for(ptr2=str;ptr1>=ptr2;)

    {

        
        if(*ptr1==*ptr2)

        {

            ptr1--;

            ptr2++;

        }

        else

            break;    

    }

    if(ptr2>ptr1)

        printf("String is Palindrome");

    else

        printf("String is not a Palindrome");

}


Output

Enter the String:madam

String is Palindrome

Enter the String:hello

String is not a Palindrome



No comments:

Post a Comment

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...