sahajjain01

Check if a string is palindrome.

Sep 21st, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. //Program to check if a string is palindrome.
  2. #include<iostream.h>
  3. #include<conio.h>
  4. #include<string.h>
  5. #include<stdio.h>
  6. void main()
  7. {
  8.     clrscr();
  9.     char a[80];
  10.     int z=1;
  11.     cout<<"Enter a string: ";
  12.     gets(a);
  13.     int n=strlen(a);
  14.     for(int i=0,j=n-1;i<=(n-1)/2;i++,j--)
  15.     {
  16.         if(a[i]!=a[j])
  17.         {
  18.             z=0;
  19.             break;
  20.         }
  21.     }
  22.     if(z==0)
  23.     cout<<"The string is not palindrome.";
  24.     else
  25.     cout<<"The string is palinrome.";
  26.     getch();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment