A C program to check whether the string is a palindrome or not, using pointers – IGNOU MCA Assignment 2013

By | September 15, 2013

MASTER OF COMPUTER APPLICATIONS
Course Code : MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/13
Assignment 2013 

 

 An interactive C program to check whether the given string is a palindrome or not, using pointers.

 

#include<stdio.h>
void main()
{
    int MID,FLAG,I,LEN=0;
    char *PTR1,*PTR2,S[50];
    clrscr();
    printf("TO CHECK PALINDROME ENTER STRING : ");
    scanf("%s",&S);
     while(S[LEN]!=NULL)
    {
       LEN++;
    };
    printf("\nTHE STRING LENGTH IS : %d",LEN);
    ;
    PTR1=&S;
    PTR2=PTR1+(LEN-1);
    MID=(LEN/2)+1;
    for(I=0;I<MID;I++)
    {
    if(*PTR1==*PTR2)
        FLAG=0;
    else
        FLAG=1;
    LEN--;
    I++;
    }
    if(FLAG==0)
    printf("\nTHE STRING IS A PALINDROME");
    else
    printf("\nTHE STRING IS NOT A PALINDROME");
    getch();
}

CODE : -

  1. #include<stdio.h>
  2. void main()
  3. {
  4.     int MID,FLAG,I,LEN=0;
  5.     char *PTR1,*PTR2,S[50];
  6.     clrscr();
  7.     printf("TO CHECK PALINDROME ENTER STRING : ");
  8.     scanf("%s",&S);
  9.      while(S[LEN]!=NULL)
  10.     {
  11.        LEN++;
  12.     };
  13.     printf("\nTHE STRING LENGTH IS : %d",LEN);
  14.     ;
  15.     PTR1=&S;
  16.     PTR2=PTR1+(LEN-1);
  17.     MID=(LEN/2)+1;
  18.     for(I=0;I<MID;I++)
  19.     {
  20.     if(*PTR1==*PTR2)
  21.         FLAG=0;
  22.     else
  23.         FLAG=1;
  24.     LEN--;
  25.     I++;
  26.     }
  27.     if(FLAG==0)
  28.     printf("\nTHE STRING IS A PALINDROME");
  29.     else
  30.     printf("\nTHE STRING IS NOT A PALINDROME");
  31.     getch();
  32. }

SCREEN SHOTS :-

MCS011_Q4

MCS011_Q4_Output

Leave a Reply