The Big Billion Days is Back On Flipkart


Latest
Check re Check the recent posts below

Follow by Email

Thursday, 20 June 2013

Q. write a program to accept a string and find out whether it is palindrome or not using pointer. ( C programming )

Palindrome using pointer:

Solution:
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
    int c=0,d;
    char str[30];char *a,*b;
    clrscr();
    printf("Enter the string:");
       scanf("%s",str);
    a=str;
    for(a=str; *a!='\0';a++);
    --a;  

    printf("a points last character now: %c",*a);
    for(b=str; *b==*a; b++)
    {
       c=c+1;
       --a;
    }

    printf("c:%d",c);
    d=strlen(str);
    if(c==d)
             printf("\nGiven String is Palindrome");
    else
             printf("\nGiven string is not palindrome");

    getch();
}


Sample Output:

 
Note: 

 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be easy way to solve this programs. So I am sorry if this program in your point of view is too long. "
 

No comments:

Post a Comment

Hello Friends...! Lets share Your Views,Ideas,Comments here....!!

Follow by Email

Popular Posts

Created by FOREVER FRIENDS