Loading
View RSS Feed

prafic

C Program To Check Whether The Given String Is Palindrome Or Not

Rating: 30 votes, 4.87 average.
/* To check the given string is palindrome or not - STRPAL.C */
Code:
# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
char str[20], rev[20] ;
int i, j, l ;
clrscr() ;
printf("Enter a string : ") ;
scanf("%s", str) ;
for(l = 0 ; str[l] != '\0' ; l++) ;
for(i = l - 1, j = 0 ; i >= 0 ; i--, j++)
rev[j] = str[i] ;
rev[j] = '\0' ;
if(strcmp(str, rev) == 0)
printf("\nThe given string is a palindrome") ;
else
printf("\nThe given string is not a palindrome") ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter a string : madam
The given string is a palindrome
RUN 2 :
~~~~~~~
Enter a string : malayalam
The given string is a palindrome

RUN 3 :
~~~~~~~
Enter a string : bhuvhu
The given string is not a palindrome

Submit "C Program To Check  Whether The Given String Is Palindrome Or Not" to Digg Submit "C Program To Check  Whether The Given String Is Palindrome Or Not" to del.icio.us Submit "C Program To Check  Whether The Given String Is Palindrome Or Not" to StumbleUpon Submit "C Program To Check  Whether The Given String Is Palindrome Or Not" to Google

Updated 11-21-2012 at 04:40 PM by Harsh

Categories
C C++

Comments

  1. Ram's Avatar
    i am happy to get connected with this forum. without even posting the question, i am getting the desired answer
  2. prafic's Avatar
    Ram if you have any question, please post them.We will try our best to give their answers.
  3. angad's Avatar
    well said prafic. you are really helpful.
  4. Nehal's Avatar
    I second Ram's and Angad's thoughts.
  5. Unregistered's Avatar
    what is "l" in the program to find whether string is palindrome or not
  6. Harsh's Avatar
    "l" acts as counter running the "for" loop
  7. ASHOK1590's Avatar
    Please write the same programme without using strreverse function...
  8. Harsh's Avatar
  9. Unregistered's Avatar
    #include <stdio.h>

    void main()
    {
    char str[]="malaxyalam";
    int i,l,j;
    for(l=0;str[l]!='\0';l++);
    i=0;
    j=l-1;
    while(i<j)
    {
    if(str[i]!=str[j])
    break;
    i++;j--;
    }
    if(i<j)
    printf("No");
    else
    printf("Yes");

    }
  10. Unregistered's Avatar
    Quote Originally Posted by prafic
    Ram if you have any question, please post them.We will try our best to give their answers.
    write a C program which asks for a User name & Password.
    The Username should have minimum 6 characters of which 1 character should be alphanumeric & 1 character should be in upper case.
    The Password should have minimum 4 characters of which 1 character should be alphanumeric, 1 character should be in lower case, 1 character should be a special character & 1 character should be in upper case.



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.